{"id":18,"date":"2015-11-04T19:49:14","date_gmt":"2015-11-04T19:49:14","guid":{"rendered":"https:\/\/html-online.com\/articles\/?p=18"},"modified":"2016-11-04T19:50:17","modified_gmt":"2016-11-04T19:50:17","slug":"overwrite-inline-styles-css","status":"publish","type":"post","link":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/","title":{"rendered":"Overwrite Inline Styles with CSS"},"content":{"rendered":"<p>We often find ourselves in situations when we want to overwrite a style we don&#8217;t have access to, it&#8217;s hard to find or we want to rewrite with CSS a style that has been written in the HTML code or has been set with Javascrpt.<br \/>\nIn this article we&#8217;re going to discuss the strength of different style declarations and how can we overwrite them.<\/p>\n<p>Let&#8217;s say we have the sentence below to start with.<\/p>\n<pre style=\"background:#fff;color:#000\"><span style=\"color:#1c02ff\">&lt;<span style=\"font-weight:700\">p<\/span>><\/span>This is our <span style=\"color:#1c02ff\">&lt;<span style=\"font-weight:700\">span<\/span> <span style=\"font-style:italic\">id<\/span>=<span style=\"color:#d80800\">\"highlighted\"<\/span>><\/span>demo text<span style=\"color:#1c02ff\">&lt;\/<span style=\"font-weight:700\">span<\/span>><\/span>.<span style=\"color:#1c02ff\">&lt;\/<span style=\"font-weight:700\">p<\/span>><\/span>\r\n<\/pre>\n<p><!--more--><br \/>\nTo highlight the span tag we would normally use CSS styles like this:<\/p>\n<pre style=\"background:#fff;color:#000\"><span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">red<\/span>;\r\n}\r\n<\/pre>\n<p>We can overwrite this if we define another color after this line in the stylesheet because always the lower rules apply. In this case the text will be blue:<\/p>\n<pre style=\"background:#fff;color:#000\"><span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">red<\/span>;\r\n}\r\n<span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">blue<\/span>;\r\n}\r\n<\/pre>\n<p>We can target more accurately the span, to set it&#8217;s color. In both cases below the color of the highlighted text will be green.<\/p>\n<pre style=\"background:#fff;color:#000\"><span style=\"font-weight:700\">span<\/span><span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">green<\/span>;\r\n}\r\n<span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">red<\/span>;\r\n}\r\n\r\n<span style=\"font-weight:700\">p<\/span> <span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">green<\/span>;\r\n}\r\n<span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">red<\/span>;\r\n}\r\n<\/pre>\n<p>Use the <em>!important<\/em> sign to override a property, regardless of its position in the document. An &#8220;!important&#8221; declaration is always stronger than one without it. It&#8217;s recommended to use these only if it&#8217;s really necessary. In our example below the text will be red.<\/p>\n<pre style=\"background:#fff;color:#000\"><span style=\"font-weight:700\">p<\/span> <span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">green<\/span>;\r\n}\r\n<span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">red<\/span> <span style=\"color:#0100b6;font-weight:700\">!important<\/span>;\r\n}\r\n<\/pre>\n<p>HTML inline styles are stronger than the CSS so in this case the text will be grey, but we can overwrite this with an !important rule from the stylesheet.<\/p>\n<pre style=\"background:#fff;color:#000\"><span style=\"font-weight:700\">p<\/span> <span style=\"font-style:italic\">#highlighted<\/span> {\r\n    <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">green<\/span>;\r\n}\r\n<\/pre>\n<pre style=\"background:#fff;color:#000\"><span style=\"color:#1c02ff\">&lt;<span style=\"font-weight:700\">p<\/span>><\/span>This is our <span style=\"color:#1c02ff\">&lt;<span style=\"font-weight:700\">span<\/span> <span style=\"font-style:italic\">id<\/span>=<span style=\"color:#d80800\">\"highlighted\"<\/span> <span style=\"font-style:italic\">style<\/span>=<span style=\"color:#d80800\">\"color: grey;\"<\/span>><\/span>demo text<span style=\"color:#1c02ff\">&lt;\/<span style=\"font-weight:700\">span<\/span>><\/span>.<span style=\"color:#1c02ff\">&lt;\/<span style=\"font-weight:700\">p<\/span>><\/span>\r\n<\/pre>\n<p>In some cases the style is reset with JavaScript \/ jQuery and we can&#8217;t overwrite it with the stylesheets. In this case we can use the strongest CSS declaration which overwrites everything:<\/p>\n<pre style=\"background:#fff;color:#000\"><span style=\"font-style:italic\">#highlighted<\/span>[style] {\r\n   <span style=\"color:#6d79de;font-weight:700\">color<\/span>: <span style=\"color:#06960e;font-weight:700\">yellow<\/span> <span style=\"color:#0100b6;font-weight:700\">!important<\/span>;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We often find ourselves in situations when we want to overwrite a style we don&#8217;t have access to, it&#8217;s hard to find or we want to rewrite with CSS a style that has been written in the HTML code or has been set with Javascrpt. In this article we&#8217;re going to discuss the strength of &hellip; <a href=\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Overwrite Inline Styles with CSS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-css","category-html"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Overwrite Inline Styles with CSS<\/title>\n<meta name=\"description\" content=\"We often find ourselves in situations when we want to overwrite a style we don&#039;t have access to, it&#039;s hard to find or we want to rewrite with CSS a style\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Overwrite Inline Styles with CSS\" \/>\n<meta property=\"og:description\" content=\"We often find ourselves in situations when we want to overwrite a style we don&#039;t have access to, it&#039;s hard to find or we want to rewrite with CSS a style\" \/>\n<meta property=\"og:url\" content=\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/\" \/>\n<meta property=\"og:site_name\" content=\"HTML Online\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/htmlcoding\/\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-04T19:49:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-11-04T19:50:17+00:00\" \/>\n<meta name=\"author\" content=\"HTML Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"HTML Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/\"},\"author\":{\"name\":\"HTML Editor\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d\"},\"headline\":\"Overwrite Inline Styles with CSS\",\"datePublished\":\"2015-11-04T19:49:14+00:00\",\"dateModified\":\"2016-11-04T19:50:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/\"},\"wordCount\":257,\"publisher\":{\"@id\":\"https:\/\/html-online.com\/articles\/#organization\"},\"articleSection\":[\"CSS\",\"HTML\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/\",\"url\":\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/\",\"name\":\"How to Overwrite Inline Styles with CSS\",\"isPartOf\":{\"@id\":\"https:\/\/html-online.com\/articles\/#website\"},\"datePublished\":\"2015-11-04T19:49:14+00:00\",\"dateModified\":\"2016-11-04T19:50:17+00:00\",\"description\":\"We often find ourselves in situations when we want to overwrite a style we don't have access to, it's hard to find or we want to rewrite with CSS a style\",\"breadcrumb\":{\"@id\":\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/html-online.com\/articles\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Overwrite Inline Styles with CSS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/html-online.com\/articles\/#website\",\"url\":\"https:\/\/html-online.com\/articles\/\",\"name\":\"HTML Online Articles\",\"description\":\"Tips, tricks, tutorials\u2026\",\"publisher\":{\"@id\":\"https:\/\/html-online.com\/articles\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/html-online.com\/articles\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/html-online.com\/articles\/#organization\",\"name\":\"HTML Online\",\"url\":\"https:\/\/html-online.com\/articles\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg\",\"contentUrl\":\"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg\",\"width\":350,\"height\":350,\"caption\":\"HTML Online\"},\"image\":{\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/htmlcoding\/\",\"https:\/\/www.linkedin.com\/in\/ferencdenes\/\",\"https:\/\/www.youtube.com\/channel\/UCn38Jw1sJzbjVHO95Zp0Sww\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d\",\"name\":\"HTML Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/html-online.com\/articles\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g\",\"caption\":\"HTML Editor\"},\"description\":\"In 2013, while wrestling with a mountain of client articles and an uncooperative CMS, I decided enough was enough. So, I created an online HTML editor purely out of necessity (and mild frustration). What began as a tool for my own sanity quickly evolved into a gift for the world\u2014or at least for anyone trying to avoid breaking their website's code. Since then, I've shared my tech notes on my blog, which serves as both a handy reference and a digital diary of the adventures and misadventures of a coder.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/ferencdenes\/\",\"https:\/\/www.youtube.com\/@htmlg\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Overwrite Inline Styles with CSS","description":"We often find ourselves in situations when we want to overwrite a style we don't have access to, it's hard to find or we want to rewrite with CSS a style","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/","og_locale":"en_GB","og_type":"article","og_title":"How to Overwrite Inline Styles with CSS","og_description":"We often find ourselves in situations when we want to overwrite a style we don't have access to, it's hard to find or we want to rewrite with CSS a style","og_url":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/","og_site_name":"HTML Online","article_publisher":"https:\/\/www.facebook.com\/htmlcoding\/","article_published_time":"2015-11-04T19:49:14+00:00","article_modified_time":"2016-11-04T19:50:17+00:00","author":"HTML Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"HTML Editor","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/#article","isPartOf":{"@id":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/"},"author":{"name":"HTML Editor","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d"},"headline":"Overwrite Inline Styles with CSS","datePublished":"2015-11-04T19:49:14+00:00","dateModified":"2016-11-04T19:50:17+00:00","mainEntityOfPage":{"@id":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/"},"wordCount":257,"publisher":{"@id":"https:\/\/html-online.com\/articles\/#organization"},"articleSection":["CSS","HTML"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/","url":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/","name":"How to Overwrite Inline Styles with CSS","isPartOf":{"@id":"https:\/\/html-online.com\/articles\/#website"},"datePublished":"2015-11-04T19:49:14+00:00","dateModified":"2016-11-04T19:50:17+00:00","description":"We often find ourselves in situations when we want to overwrite a style we don't have access to, it's hard to find or we want to rewrite with CSS a style","breadcrumb":{"@id":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/html-online.com\/articles\/overwrite-inline-styles-css\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/html-online.com\/articles\/"},{"@type":"ListItem","position":2,"name":"Overwrite Inline Styles with CSS"}]},{"@type":"WebSite","@id":"https:\/\/html-online.com\/articles\/#website","url":"https:\/\/html-online.com\/articles\/","name":"HTML Online Articles","description":"Tips, tricks, tutorials\u2026","publisher":{"@id":"https:\/\/html-online.com\/articles\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/html-online.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/html-online.com\/articles\/#organization","name":"HTML Online","url":"https:\/\/html-online.com\/articles\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/","url":"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg","contentUrl":"https:\/\/html-online.com\/articles\/wp-content\/uploads\/2022\/06\/logo.jpg","width":350,"height":350,"caption":"HTML Online"},"image":{"@id":"https:\/\/html-online.com\/articles\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/htmlcoding\/","https:\/\/www.linkedin.com\/in\/ferencdenes\/","https:\/\/www.youtube.com\/channel\/UCn38Jw1sJzbjVHO95Zp0Sww"]},{"@type":"Person","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/019f9afa07f209153df0fecfc90b8c1d","name":"HTML Editor","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/html-online.com\/articles\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7c1d8f5e7f1dc3e261766a96ac50c6a907fa5c236e87ab73379c57c9114e92cd?s=96&d=mm&r=g","caption":"HTML Editor"},"description":"In 2013, while wrestling with a mountain of client articles and an uncooperative CMS, I decided enough was enough. So, I created an online HTML editor purely out of necessity (and mild frustration). What began as a tool for my own sanity quickly evolved into a gift for the world\u2014or at least for anyone trying to avoid breaking their website's code. Since then, I've shared my tech notes on my blog, which serves as both a handy reference and a digital diary of the adventures and misadventures of a coder.","sameAs":["https:\/\/www.linkedin.com\/in\/ferencdenes\/","https:\/\/www.youtube.com\/@htmlg"]}]}},"_links":{"self":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":1,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":19,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/posts\/18\/revisions\/19"}],"wp:attachment":[{"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html-online.com\/articles\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}