{"id":14158,"date":"2011-09-06T19:51:23","date_gmt":"2011-09-07T02:51:23","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=14158"},"modified":"2022-09-30T12:06:53","modified_gmt":"2022-09-30T19:06:53","slug":"after-and-before","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/selectors\/a\/after-and-before\/","title":{"rendered":"::before \/ ::after"},"content":{"rendered":"\n

The ::before<\/code> and ::after<\/code> pseudo-elements in CSS allows you to insert content onto a page without it needing to be in the HTML. While the end result is not actually in the DOM, it appears on the page as if it is, and would essentially be like this:<\/p>\n\n\n\n

div::before {\n  content: \"before\";\n}\ndiv::after {\n  content: \"after\";\n}<\/code><\/pre>\n\n\n\n
<div>\n  before\n  <!-- Rest of stuff inside the div -->\n  after\n<\/div><\/code><\/pre>\n\n\n\n

The only reasons to use one over the other are:<\/p>\n\n\n\n