{"id":159,"date":"2026-04-07T04:53:57","date_gmt":"2026-04-07T04:53:57","guid":{"rendered":"https:\/\/gigz.pk\/css\/?post_type=lesson&#038;p=159"},"modified":"2026-04-07T04:53:58","modified_gmt":"2026-04-07T04:53:58","slug":"pseudo-elements-before-after","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/","title":{"rendered":"Pseudo-elements (::before, ::after)"},"content":{"rendered":"\n<p>Pseudo-elements allow you to style specific parts of an element or insert content without changing the HTML. The most commonly used pseudo-elements are ::before and ::after.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What are ::before and ::after<\/h3>\n\n\n\n<p>::before inserts content before the actual content of an element.<br>::after inserts content after the actual content of an element.<\/p>\n\n\n\n<p>These are useful for adding decorative elements, icons, labels, or effects without extra HTML tags.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Syntax<\/h3>\n\n\n\n<p>selector::before {<br>content: &#8220;Text or empty&#8221;;<br>}<\/p>\n\n\n\n<p>selector::after {<br>content: &#8220;Text or empty&#8221;;<br>}<\/p>\n\n\n\n<p>The content property is required. Without it, the pseudo-element will not appear.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 1 Adding Text<\/h3>\n\n\n\n<p>p::before {<br>content: &#8220;Note: &#8220;;<br>color: red;<br>}<\/p>\n\n\n\n<p>This will automatically add the word &#8220;Note:&#8221; before every paragraph.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 2 Decorative Styling<\/h3>\n\n\n\n<p>h2::after {<br>content: &#8220;&#8221;;<br>display: block;<br>width: 50px;<br>height: 3px;<br>background-color: black;<br>}<\/p>\n\n\n\n<p>This creates a line below each heading without adding extra HTML.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 3 Button Hover Effect<\/h3>\n\n\n\n<p>button::after {<br>content: &#8221; \u2192&#8221;;<br>}<\/p>\n\n\n\n<p>button:hover::after {<br>color: blue;<br>}<\/p>\n\n\n\n<p>This adds an arrow after the button text and changes color on hover.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 4 Using Icons<\/h3>\n\n\n\n<p>li::before {<br>content: &#8220;\u2714 &#8220;;<br>color: green;<br>}<\/p>\n\n\n\n<p>This adds a check icon before each list item.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Positioning Pseudo-elements<\/h3>\n\n\n\n<p>You can position pseudo-elements using CSS positioning.<\/p>\n\n\n\n<p>div {<br>position: relative;<br>}<\/p>\n\n\n\n<p>div::before {<br>content: &#8220;&#8221;;<br>position: absolute;<br>top: 0;<br>left: 0;<br>}<\/p>\n\n\n\n<p>This allows you to place elements exactly where needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Important Notes<\/h3>\n\n\n\n<p>Pseudo-elements do not work on all HTML elements such as input fields.<br>They are mainly used for styling and decoration, not important content.<br>Always use content property even if it is empty.<br>They help keep HTML clean and reduce extra tags.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Practice Task<\/h3>\n\n\n\n<p>Create a card design where<br>A label appears before the title using ::before<br>A decorative line appears after the title using ::after<\/p>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-159","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Pseudo-elements (::before, ::after) - CSS learning mastery<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pseudo-elements (::before, ::after) - CSS learning mastery\" \/>\n<meta property=\"og:description\" content=\"Pseudo-elements allow you to style specific parts of an element or insert content without changing the HTML. The most commonly used pseudo-elements are ::before and ::after. What are ::before and ::after ::before inserts content before the actual content of an element.::after inserts content after the actual content of an element. These are useful for adding [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/\" \/>\n<meta property=\"og:site_name\" content=\"CSS learning mastery\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-07T04:53:58+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-elements-before-after\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-elements-before-after\\\/\",\"name\":\"Pseudo-elements (::before, ::after) - CSS learning mastery\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\"},\"datePublished\":\"2026-04-07T04:53:57+00:00\",\"dateModified\":\"2026-04-07T04:53:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-elements-before-after\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-elements-before-after\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-elements-before-after\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pseudo-elements (::before, ::after)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\",\"name\":\"CSS learning mastery\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/css\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pseudo-elements (::before, ::after) - CSS learning mastery","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:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/","og_locale":"en_US","og_type":"article","og_title":"Pseudo-elements (::before, ::after) - CSS learning mastery","og_description":"Pseudo-elements allow you to style specific parts of an element or insert content without changing the HTML. The most commonly used pseudo-elements are ::before and ::after. What are ::before and ::after ::before inserts content before the actual content of an element.::after inserts content after the actual content of an element. These are useful for adding [&hellip;]","og_url":"https:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/","og_site_name":"CSS learning mastery","article_modified_time":"2026-04-07T04:53:58+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/","url":"https:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/","name":"Pseudo-elements (::before, ::after) - CSS learning mastery","isPartOf":{"@id":"https:\/\/gigz.pk\/css\/#website"},"datePublished":"2026-04-07T04:53:57+00:00","dateModified":"2026-04-07T04:53:58+00:00","breadcrumb":{"@id":"https:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/css\/lesson\/pseudo-elements-before-after\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/css\/"},{"@type":"ListItem","position":2,"name":"Pseudo-elements (::before, ::after)"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/css\/#website","url":"https:\/\/gigz.pk\/css\/","name":"CSS learning mastery","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/css\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/media?parent=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}