
- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Advanced Features
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - Fonts
CSS fonts allows to customize font style of webpages using various font related properties. In this tutorial we will understand the font styling in CSS.
What is CSS Font?
In CSS, the font property is used to style and adjust type of text used in webpage.
You can define fonts and customize their appearance by setting properties like font-family, font-size, font-weight and font-style. You can also use the shorthand property font to manipulate all the font style.
Types of CSS Fonts
- Monospace Fonts: The font in which every letter have equal width.
- Serif Fonts: Have small stroke at the edge of each letter.
- San-Serif Fonts: Clean fonts with out any strokes.
- Fantasy Fonts: Decorative fancy fonts.
- Cursive Fonts: The font that resembles human handwriting.
Popular CSS Fonts
Here is a table with some popular font and their generic font-family.
Generic Font Family | Examples of Font Names |
---|---|
Serif |
Times New Roman Georgia Garamond |
Sans-serif |
Arial Verdana Helvetica |
Monospace |
Courier New Lucida Console Monaco |
Cursive |
Brush Script MT Lucida Handwriting |
Fantasy |
Copperplate Papyrus |
Setting Text Fonts
The font-family property is used to specify font name for a text content.
Example
In this example, we have used the font-family property to set the font of the paragraph element.
<html> <head> <style> p { font-family: Lucida Handwriting, Cursive; } </style> </head> <body> <p > This is a font that written in Lucida Handwriting. THis is a font that looks like human handwriting. </p> </body> </html>
Setting Text Font Size
To set the font size of the text, we use font-size property. You can use its values such as small, medium, and, large to get a variety of font sizes of the text.
Example
In this example, we have used the font-size property with its different values to set the size of the text.
<!DOCTYPE html> <html lang="en"> <head> <title>Font Size Example</title> <style> .small { font-size: small; } .medium { font-size: medium; } .larger { font-size: larger; } .px { font-size: 18px; } .percent { font-size: 120%; } </style> </head> <body> <h2>CSS Font-Size Examples</h2> <p class="small">This text has a 'small' font size.</p> <p class="medium">This text has a 'medium' font size.</p> <p class="larger">This text has a 'larger' font size.</p> <p class="px">This text has a font size of 18px.</p> <p class="percent">This text has a font size of 25%.</p> </body> </html>
Setting Font Weight
You can use the font-weight property to set the boldness of the text.
Example
In this example, we have used the font-weight property to set the boldness of the text. The valid numeric value is from 100-900 for number class.
<!DOCTYPE html> <html lang="en"> <head> <title>CSS font-weight Property Example</title> <style> .normal { font-weight: normal; } .bold { font-weight: bold; } .lighter { font-weight: lighter; } .number { font-weight: 600; } </style> </head> <body> <h2>CSS font-weight Property</h2> <p class="normal">This text has a 'normal' font-weight.</p> <p class="bold">This text has a 'bold' font-weight.</p> <p class="lighter">This text has a 'lighter' font-weight.</p> <p class="number">This text has a font-weight of 600.</p> </body> </html>
Setting Font Style
To set the style of the written text, we use the font-style property. The text can be set to normal, italic or oblique.
Example
In this example, we have used font-style property to set the style of the written text.
<!DOCTYPE html> <html lang="en"> <head> <title>CSS font-style Property Example</title> <style> .normal { font-style: normal; } .italic { font-style: italic; } .oblique { font-style: oblique; } </style> </head> <body> <h2>CSS font-style Property</h2> <p class="normal">It has 'normal' font-style.</p> <p class="italic">It has 'italic' font-style.</p> <p class="oblique">It has 'oblique' font-style.</p> </body> </html>
CSS Font Shorthand Property
You can use the font shorthand property to modify size, weight, and style of texts.
Example
In this example, we have used the font shorthand property to set font style, weight, size and family.
<html> <head> <style> .font-example { /* in-order: font style, weight, size, family */ font: italic bold 20px Arial, sans-serif; } </style> </head> <body> <p class="font-example"> This is an example of text with an adjusted font style, weight, and size using the font shorthand property. </p> </body> </html>
CSS Font Related Properties
The following table lists all the CSS properties related to font:
Property | Description | Example |
---|---|---|
font-family | Specifies the font for an element. | |
font-size | Specifies the size of the font. | |
font-weight | Specifies the boldness of the font. | |
font-style | Specifies the style of the font (normal, italic, oblique). | |
font-variant | Specifies whether or not a text should be displayed in a small-caps font. | |
line-height | Specifies the line height. |