{"id":14256,"date":"2012-07-11T21:03:38","date_gmt":"2012-07-11T13:03:38","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=14256"},"modified":"2025-04-24T17:08:38","modified_gmt":"2025-04-24T09:08:38","slug":"pseudo-element-before-after","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/","title":{"rendered":"Understanding Pseudo-Element :before and :after"},"content":{"rendered":"<p>Cascading Style Sheet (<a href=\"https:\/\/www.hongkiat.com\/blog\/tag\/css\/\">CSS<\/a>) is primarily  intended for applying styles to the <a href=\"https:\/\/www.hongkiat.com\/blog\/tag\/css\/\">HTML<\/a> markup, however in some cases when adding extra markup to the document is redundant or not possible, there is actually a feature in CSS that allows us to add extra markup without disrupting the actual document, namely the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.w3.org\/TR\/selectors\/#pseudo-elements\"><em>pseudo-elements<\/em><\/a>.<\/p>\n<p>You have heard of this term, especially when you have been following some of <a href=\"https:\/\/www.hongkiat.com\/blog\/tag\/css+coding\/\" rel=\"nofollow\">our  tutorials<\/a>.<\/p>\n<p>There are actually a few CSS family members that are classified as <code>pseudo-elements<\/code> such as the <code>:first-line<\/code>, <code>:first-letter<\/code>, <code>::selection<\/code>, <code>:before<\/code> and <code>:after<\/code>. But, for this article, we will limit our coverage to only the <code>:before<\/code> and <code>:after<\/code>; <em>pseudo-elements<\/em> here will specifically refer to both of them. We will look into this particular subject starting with the basics.<\/p>\n<h2>The Syntax and Browser Support<\/h2>\n<p>The <em>pseudo-elements<\/em> have actually been around <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.sitepoint.com\/css-pseudo-elements\/\">since <strong>CSS1<\/strong><\/a>, but the <code>:before<\/code> and <code>:after<\/code> that we are discussing here were released in <strong>CSS2.1<\/strong>. At the beginning, the <em>pseudo-elements<\/em> used single-colon for the syntax, then as the web evolved, in CSS3 the <em>pseudo-elements<\/em> were revised to use double-colon \u2013 becoming <code>::before<\/code> & <code>::after<\/code> \u2013 to distinguish them from <em>pseudo-classes<\/em> (i.e. <code>:hover<\/code>, <code>:active<\/code>, and so on).<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" alt=\"syntax\" height=\"280\" src=\"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/syntax.jpg\" width=\"500\"><\/figure>\n<p>However, whether you use the single-colon or the double-colon format, the browsers will still recognize either. And since Internet Explorer 8 only supports the single-colon format, it is safer to use the single-colon if you want <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.sitepoint.com\/css-pseudo-elements\/\">wider browser compatibility<\/a>.<\/p>\n<h3>What does it do?<\/h3>\n<p>In short, the <em>pseudo-elements<\/em> will insert an extra element <strong>before<\/strong> or <strong>after<\/strong> the content\u2019s element, so when we add them both, they are technically equivalent to the following markup.<\/p>\n<pre>\n&lt;p&gt;\n  &lt;span&gt;:before&lt;\/span&gt;\n  This the main content.\n  &lt;span&gt;:after&lt;\/span&gt;\n&lt;\/p&gt;\n<\/pre>\n<p>But those elements are not actually generated on the document. They are still visible on the surface, but you will not find them on the document source, so practically speaking they are <strong>fake<\/strong> elements.<\/p>\n<h2>Using pseudo-elements<\/h2>\n<p>Using <em>pseudo-elements<\/em> is relatively easy; the following syntax <code>selector:before<\/code> will add an element <strong>before<\/strong> the content\u2019s selector while this syntax <code>selector:after<\/code> will add an element after it, and to add a content inside them we can use the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.w3schools.com\/cssref\/pr_gen_content.asp\"><code>content<\/code> property<\/a>.<\/p>\n<p>For example, the snippet below will add a quotation mark before and after the <code>blockquote<\/code>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" alt=\"quotation mark\" height=\"280\" src=\"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/quotationmark.jpg\" width=\"500\"><\/figure>\n<pre>\nblockquote:before {\n  content: open-quote;\n}\nblockquote:after {\n  content: close-quote;\n}\n<\/pre>\n<h3>Styling pseudo-elements<\/h3>\n<p>Despite being fake elements, the <em>pseudo-elements<\/em> actually act like \u201creal\u201d elements; we are able to add any style declarations to them, such as changing the color, adding background, adjusting the font size, aligning the text inside it and so forth.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" alt=\"image styles\" height=\"280\" src=\"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/styles.jpg\" width=\"500\"><\/figure>\n<pre>\nblockquote:before {\n  content: open-quote;\n  font-size: 24pt;\n  text-align: center;\n  line-height: 42px;\n  color: #fff;\n  background: #ddd;\n  float: left;\n  position: relative;\n  top: 30px;\n}\nblockquote:after {\n  content: close-quote;\n  font-size: 24pt;\n  text-align: center;\n  line-height: 42px;\n  color: #fff;\n  background: #ddd;\n  float: right;\n  position: relative;\n  bottom: 40px;\n}\n<\/pre>\n<h3>Specifying the dimension<\/h3>\n<p>The generated elements are by default <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.thoughtco.com\/normal-flow-definition-3467023\">inline-level element<\/a>, so when we are about to specify the height and the width, we have to first define them as block elements using the <code>display: block<\/code> declaration.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" alt=\"image dimension\" height=\"280\" src=\"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/dimension.jpg\" width=\"500\"><\/figure>\n<pre>\nblockquote:before {\n  content: open-quote;\n  font-size: 24pt;\n  text-align: center;\n  line-height: 42px;\n  color: #fff;\n  background: #ddd;\n  float: left;\n  position: relative;\n  top: 30px;\n  border-radius: 25px;\n\n  \/* define it as a block element *\/\n  display: block;\n  height: 25px;\n  width: 25px;\n}\nblockquote:after {\n  content: close-quote;\n  font-size: 24pt;\n  text-align: center;\n  line-height: 42px;\n  color: #fff;\n  background: #ddd;\n  float: right;\n  position: relative;\n  bottom: 40px;\n  border-radius: 25px;\n\n  \/* define it as a block element *\/\n  display: block;\n  height: 25px;\n  width: 25px;\n}\n<\/pre>\n<h3>Attach background image<\/h3>\n<p>We can also replace the content with an image rather than only plain text. Although the <code>content<\/code> property provides a <code>url()<\/code> string to insert an image, in most cases I much prefer using the <code>background<\/code> property for more control over the image attached.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" alt=\"image background\" height=\"280\" src=\"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/image-background.jpg\" width=\"500\"><\/figure>\n<pre>\nblockquote:before {\n  content: \" \";\n  font-size: 24pt;\n  text-align: center;\n  line-height: 42px;\n  color: #fff;\n  float: left;\n  position: relative;\n  top: 30px;\n  border-radius: 25px;\n\n  background: url(images\/quotationmark.png) -3px -3px #ddd;\n\n  display: block;\n  height: 25px;\n  width: 25px;\n}\nblockquote:after {\n  content: \" \";\n  font-size: 24pt;\n  text-align: center;\n  line-height: 42px;\n  color: #fff;\n  float: right;\n  position: relative;\n  bottom: 40px;\n  border-radius: 25px;\n\n  background: url(images\/quotationmark.png) -1px -32px #ddd;\n\n  display: block;\n  height: 25px;\n  width: 25px;\n}\n<\/pre>\n<p>However, as you can see from the snippet above, we are still declaring the <code>content<\/code> property, this time with an empty string. The <code>content<\/code> property is <strong>a requirement<\/strong> and should always be applied; otherwise the <em>pseudo-element<\/em> <strong>will not work<\/strong> whatsoever.<\/p>\n<h3>Combining with pseudo-classes<\/h3>\n<p>Although they are a different kind of <em>pseudo<\/em>, we can use <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.sitepoint.com\/pseudo-classes-the-basics\/\">the <em>pseudo-classes<\/em><\/a> along with <em>pseudo-elements<\/em> together in one CSS rule, for instance, if we want to make the <strong>quotation mark background<\/strong> a bit darker when we hover over the <code>blockquote<\/code>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" alt=\"image hover\" height=\"280\" src=\"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/hover.jpg\" width=\"500\"><\/figure>\n<pre>\nblockquote:hover:after, blockquote:hover:before {\n  background-color: #555;\n}\n<\/pre>\n<h3>Adding Transition Effect<\/h3>\n<p>And we can even apply the <code>transition<\/code> property to them to create a graceful color transition effect.<\/p>\n<pre>\ntransition: all 350ms;\n-o-transition: all 350ms;\n-moz-transition: all 350ms;\n-webkit-transition: all 350ms;\n<\/pre>\n<p>Unfortunately though, the transition effect seems to only work in <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.mozilla.org\/en-US\/firefox\/new\/\">the latest version of Firefox<\/a>. Hopefully <a href=\"https:\/\/www.hongkiat.com\/blog\/20-awesome-battle-of-the-browsers-artworks\/\">more browsers<\/a> will catch up to allow the transition property to be applied to <em>pseudo-elements<\/em> in the future.<\/p>\n<div class=\"button\">\n    <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/demo\/index.html\">Demo<\/a>\n    <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/demo\/source.zip\">Download Source<\/a>\n<\/div>\n<h2>Conclusion<\/h2>\n<p><em>Pseudo-elements<\/em> are simply <strong>cool<\/strong> and ultimately usable. Basically, we have <strong>two bonus elements<\/strong> for every element we add without interfering with the actual HTML structure at all, and then turning them into <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.w3schools.com\/css\/css_pseudo_elements.asp\">almost everything we can ever imagine<\/a>.<\/p>\n<p>There are actually <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.w3.org\/TR\/css3-content\/\">some improvements for <em>pseudo-elements<\/em><\/a> that are currently being worked on, such as <strong>nesting pseudo-elements<\/strong> <code>div::before::before { content: ''; }<\/code> and <strong>multiple pseudo-elements<\/strong> <code>div::before(3) { content: ''; }<\/code>, which obviously will open much more possibilities in web design practice in the future. While they are being implemented in current browsers, let\u2019s wait patiently for now.<\/p>","protected":false},"excerpt":{"rendered":"<p>Cascading Style Sheet (CSS) is primarily intended for applying styles to the HTML markup, however in some cases when adding extra markup to the document is redundant or not possible, there is actually a feature in CSS that allows us to add extra markup without disrupting the actual document, namely the pseudo-elements. You have heard&hellip;<\/p>\n","protected":false},"author":113,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[507,2060],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Understanding Pseudo-Element :before and :after - Hongkiat<\/title>\n<meta name=\"description\" content=\"Cascading Style Sheet (CSS) is primarily intended for applying styles to the HTML markup, however in some cases when adding extra markup to the document\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Understanding Pseudo-Element :before and :after\" \/>\n<meta property=\"og:description\" content=\"Cascading Style Sheet (CSS) is primarily intended for applying styles to the HTML markup, however in some cases when adding extra markup to the document\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2012-07-11T13:03:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T09:08:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/syntax.jpg\" \/>\n<meta name=\"author\" content=\"Thoriq Firdaus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@tfirdaus\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Thoriq Firdaus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/\"},\"author\":{\"name\":\"Thoriq Firdaus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\"},\"headline\":\"Understanding Pseudo-Element :before and :after\",\"datePublished\":\"2012-07-11T13:03:38+00:00\",\"dateModified\":\"2025-04-24T09:08:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/\"},\"wordCount\":687,\"commentCount\":60,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/before-after-elements\\\/syntax.jpg\",\"keywords\":[\"CSS\",\"pseudo element\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/\",\"name\":\"Understanding Pseudo-Element :before and :after - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/before-after-elements\\\/syntax.jpg\",\"datePublished\":\"2012-07-11T13:03:38+00:00\",\"dateModified\":\"2025-04-24T09:08:38+00:00\",\"description\":\"Cascading Style Sheet (CSS) is primarily intended for applying styles to the HTML markup, however in some cases when adding extra markup to the document\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/before-after-elements\\\/syntax.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/before-after-elements\\\/syntax.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/pseudo-element-before-after\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Understanding Pseudo-Element :before and :after\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\",\"name\":\"Thoriq Firdaus\",\"description\":\"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.\",\"sameAs\":[\"https:\\\/\\\/thoriq.com\",\"https:\\\/\\\/x.com\\\/tfirdaus\"],\"jobTitle\":\"Web Developer\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/thoriq\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Understanding Pseudo-Element :before and :after - Hongkiat","description":"Cascading Style Sheet (CSS) is primarily intended for applying styles to the HTML markup, however in some cases when adding extra markup to the document","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:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/","og_locale":"en_US","og_type":"article","og_title":"Understanding Pseudo-Element :before and :after","og_description":"Cascading Style Sheet (CSS) is primarily intended for applying styles to the HTML markup, however in some cases when adding extra markup to the document","og_url":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2012-07-11T13:03:38+00:00","article_modified_time":"2025-04-24T09:08:38+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/syntax.jpg","type":"","width":"","height":""}],"author":"Thoriq Firdaus","twitter_card":"summary_large_image","twitter_creator":"@tfirdaus","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Thoriq Firdaus","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/"},"author":{"name":"Thoriq Firdaus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807"},"headline":"Understanding Pseudo-Element :before and :after","datePublished":"2012-07-11T13:03:38+00:00","dateModified":"2025-04-24T09:08:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/"},"wordCount":687,"commentCount":60,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/syntax.jpg","keywords":["CSS","pseudo element"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/","url":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/","name":"Understanding Pseudo-Element :before and :after - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/syntax.jpg","datePublished":"2012-07-11T13:03:38+00:00","dateModified":"2025-04-24T09:08:38+00:00","description":"Cascading Style Sheet (CSS) is primarily intended for applying styles to the HTML markup, however in some cases when adding extra markup to the document","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/syntax.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/before-after-elements\/syntax.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/pseudo-element-before-after\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Understanding Pseudo-Element :before and :after"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807","name":"Thoriq Firdaus","description":"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.","sameAs":["https:\/\/thoriq.com","https:\/\/x.com\/tfirdaus"],"jobTitle":"Web Developer","url":"https:\/\/www.hongkiat.com\/blog\/author\/thoriq\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-3HW","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/14256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/113"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=14256"}],"version-history":[{"count":4,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/14256\/revisions"}],"predecessor-version":[{"id":74100,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/14256\/revisions\/74100"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=14256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=14256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=14256"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=14256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}