Fireship · @fireship
3 More Life-Changing CSS Tips
Uploaded April 14, 2021 · Length 2:59
Summary
learn 3 simple yet powerful css techniques to improve your web design: using relative units, hsl colors, and scroll padding.
- css tips
- responsive design
- hsl colors
- scroll padding
- web development
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
a few days ago i shared 10 of my
- 0:01
favorite css techniques
- 0:03
and you guys responded with nearly a
- 0:04
thousand comments of your own pro tips
- 0:06
tips that are so good that they deserve
- 0:08
their own video
- 0:09
the first one from skylark murphy is
- 0:11
really simple yet really powerful
- 0:13
basically it boils down to use relative
- 0:15
units when possible over static pixel
- 0:17
values for example
- 0:18
when designing a responsive layout you
- 0:20
might have headings or containers with
- 0:22
fixed pixel values for margin and
- 0:24
padding then you might have a media
- 0:25
query to change those values on smaller
- 0:27
screens
- 0:28
not only is this difficult to maintain
- 0:29
but it doesn't work very well on devices
- 0:31
that scale fonts automatically
- 0:33
instead of fixed units like pixels we
- 0:35
can use relative units like
- 0:36
m or rem m will calculate the size
- 0:39
automatically
- 0:40
based on the font size of its nearest
- 0:41
parent if the parent has a font size of
- 0:43
16 pixels
- 0:45
then 2m would compute to 32 pixels as an
- 0:48
alternative
- 0:48
you could use rem which is relative to
- 0:50
the root font size i generally find that
- 0:52
one more useful when working with margin
- 0:54
and padding
- 0:55
but most importantly notice how that got
- 0:56
rid of the media query and one thing
- 0:58
i'll add is that there are more relative
- 0:59
units than just
- 1:00
m and rem one of which is ch or
- 1:03
character width
- 1:04
now if you're really serious about
- 1:05
design you may have read the elements of
- 1:07
typographic style by robert bringhurst
- 1:09
which says that the optimal size for a
- 1:11
paragraph is between
- 1:12
45 and 75 characters a cool trick is
- 1:15
that we can enforce that rule using the
- 1:17
clamp function i showed you in the
- 1:18
previous video
- 1:19
use it to make the min width 45
- 1:21
characters the preferred width 50
- 1:23
and the max width 75 characters and now
- 1:25
every paragraph will be the absolute
- 1:27
perfect width now our next tip is also
- 1:29
very simple but also one that will
- 1:30
change your life
- 1:31
dimitra says to use hsl colors over hex
- 1:34
or rgb
- 1:35
rgb stands for red green blue where each
- 1:37
mix of the color can be a value from 0
- 1:39
to
- 1:40
255. hexadecimal contains the same
- 1:42
information but in a more compact format
- 1:44
that's even harder to interpret
- 1:46
hsl on the other hand stands for hue
- 1:48
saturation and lightness
- 1:50
and that format makes it way easier to
- 1:52
compute a nice looking color palette if
- 1:54
you have a hex color in vs code
- 1:55
go ahead and hover over it then click on
- 1:57
the top to bring up hsl mode on the
- 1:59
right you'll notice we have our cue


