Fireship · @fireship
CSS Pseudo-elements :: in 100 Seconds
Uploaded June 8, 2020 · Length 1:57
Summary
Learn how to use CSS pseudo-elements to style HTML parts without markup duplication, improving code efficiency and maintainability.
- css pseudo-elements
- html styling
- css efficiency
- web development
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
pseudo elements there's more to your
- 0:02
HTML than meets the eye there are parts
- 0:04
of the UI that you can style with CSS
- 0:05
that don't actually exist in your HTML
- 0:07
markup take for example a form input
- 0:09
that has some placeholder text the
- 0:11
placeholder value is defined as an
- 0:13
attribute on the element so how do we
- 0:14
get ahold of the placeholder to style it
- 0:16
the answer is we target a pseudo element
- 0:18
in our CSS they always have a double
- 0:20
colon to distinguish them from pseudo
- 0:22
classes the difference is that a pseudo
- 0:24
element represents an actual part of the
- 0:26
Dom whereas a pseudo class represents
- 0:28
the state of an element based on the
- 0:30
user's interaction with it pseudo
- 0:31
elements can make your code much more
- 0:33
efficient take for example this HTML
- 0:35
where the first letter in each paragraph
- 0:37
is being wrapped in a span so it can be
- 0:39
styled a far more efficient way to solve
- 0:41
this problem is by targeting the first
- 0:42
letter on the paragraph element the end
- 0:44
result is much cleaner semantic HTML
- 0:46
that's cool but by far the most powerful
- 0:48
pseudo elements are before and after
- 0:50
many but not all HTML elements can have
- 0:53
content inserted before or after their
- 0:55
inner content handled entirely from your
- 0:57
CSS code for example we can target
- 0:59
before and provide an empty string as
- 1:01
the content property now that we've
- 1:03
targeted this element you'll notice that
- 1:04
it shows up in the browser's inspector
- 1:06
we can style this element as if it were
- 1:08
an empty span or div in our HTML and
- 1:10
that can be very useful for creating
- 1:11
advanced animations without polluting
- 1:13
your HTML markup imagine we have a big
- 1:15
unordered list and before each list item
- 1:17
we have an emoji character instead of
- 1:19
duplicating it in the markup we can
- 1:21
simply add it as the content property to
- 1:23
the before selector and once again we're
- 1:25
left with code that is far more
- 1:26
maintainable there's a few other pseudo
- 1:28
elements that you should know about
- 1:29
selection allows you to change the
- 1:31
background and color of highlighted text
- 1:33
in some browsers like chrome but not
- 1:34
Firefox you can customize the scroll bar
- 1:36
on scrollable elements before using the
- 1:38
pseudo element always check for browser
- 1:40
compatibility ones like spelling error
- 1:42
might sound cool but they don't really
- 1:43
have any browser support yet this has
- 1:45
been pseudo elements in 100 seconds make
- 1:47
sure to also check out pseudo classes
- 1:48
thanks for watching and I will see you
- 1:50
in the next one
- 1:52
you


