CSS Typography
Enhance text styling and readability with advanced CSS typography
Introduction to CSS Typography
Typography in CSS refers to the styling and arrangement of text to make it legible, readable, and appealing. Good typography enhances the user experience by making content easier to read and understand.
CSS provides a wide range of properties to control typography, from basic font styling to advanced features like ligatures, kerning, and variable fonts.
Font Family
The font-family
property specifies the font for an element. You can provide multiple font names as a "fallback" system.
This text is in a serif font. font-family: Georgia, Times, "Times New Roman", serif;
This text is in a sans-serif font. font-family: Arial, Helvetica, sans-serif;
This text is in a monospace font. font-family: "Courier New", Courier, monospace;
This text is in a cursive font. font-family: "Brush Script MT", cursive;
This text is in a fantasy font. font-family: Papyrus, fantasy;
Font Size
The font-size
property sets the size of the text. There are several units you can use:
This text is 18px. font-size: 18px;
This text is 1.2em (relative to parent). font-size: 1.2em;
This text is 1.2rem (relative to root). font-size: 1.2rem;
This text is 120% (relative to parent). font-size: 120%;
Font Weight
The font-weight
property sets how thick or thin characters in text should be displayed.
This text has a weight of 100 (Thin). font-weight: 100;
This text has a weight of 300 (Light). font-weight: 300;
This text has a weight of 400 (Normal). font-weight: 400;
This text has a weight of 700 (Bold). font-weight: 700;
This text has a weight of 900 (Black). font-weight: 900;
Font Style
The font-style
property specifies the style of the font.
This text has normal style. font-style: normal;
This text is italic. font-style: italic;
This text is oblique. font-style: oblique;
Text Decoration
The text-decoration
property sets the decoration added to text.
This text has no decoration. text-decoration: none;
This text is underlined. text-decoration: underline;
This text has an overline. text-decoration: overline;
This text has a line through it. text-decoration: line-through;
This text has a wavy underline. text-decoration: underline wavy #5e72e4;
This text has a dotted underline. text-decoration: underline dotted #ea5455;
Text Transform
The text-transform
property controls the capitalization of text.
This text has no transformation. text-transform: none;
This text is uppercase. text-transform: uppercase;
This Text Is Lowercase. text-transform: lowercase;
this text is capitalized. text-transform: capitalize;
Text Alignment
The text-align
property specifies the horizontal alignment of text in an element.
This text is aligned to the left. text-align: left;
This text is centered. text-align: center;
This text is aligned to the right. text-align: right;
This text is justified. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. Vivamus hendrerit arcu sed erat molestie vehicula. text-align: justify;
Line Height
The line-height
property specifies the height of a line, which affects the spacing between lines of text.
This text has normal line height. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. line-height: normal;
This text has a line height of 1.5. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. line-height: 1.5;
This text has a line height of 2. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. line-height: 2;
Text Shadow
The text-shadow
property adds shadow to text.
This text has a basic shadow. text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
This text has a glow effect. text-shadow: 0 0 10px #5e72e4;
This text has an outline. text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
Typography Combinations
Combining different typography properties can create cohesive and visually appealing text styles.
This is a Heading Style
This is a Subheading Style
This is body text style. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris. Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor.
This is a quote style. "Typography is what language looks like."
Responsive Typography
Responsive typography adjusts to different screen sizes, ensuring readability across devices.
This heading scales with viewport
This text also scales with the viewport size. Resize your browser to see how the text size adjusts automatically. This approach creates a smooth scaling effect without breakpoints.