
- 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 - font-size Property
CSS font-size property sets the size of the font for an elements text. It can be defined using various units like pixels, ems, rems, percentages, or keywords, impacting text readability, layout, and overall design consistency across different devices and resolutions.
Syntax
font-size: medium | xx-small | x-small | small | large | x-large | xx-large | smaller | larger | length | percentage | initial | inherit;
Property Values
Value | Description |
---|---|
medium | It sets the element's font size as medium. |
xx-small | It sets the element's font size as xx-small. |
x-small | It sets the element's font size as x-small. |
small | It sets the element's font size as small. |
large | It sets the element's font size as large. |
x-large | It sets the element's font size as x-large. |
xx-large | It sets the element's font size as xx-large. |
smaller | It sets the element's font size as smaller. |
larger | It sets the element's font size as larger. |
length | The font size of the element is specified in length units (px, em, rems etc.) |
percentage | The font size of the element is specified in percentage. |
initial | It sets the property to its initial value. |
inherit | It inherits the property from the parent element. |
Examples of CSS Font Size Property
The following examples explain the font-size property with different values.
Font Size Property with Medium Value
To set a medium size to the element's font, we use the medium value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .font { font-size: medium; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="font"> This text has a medium size. </p> </body> </html>
Font Size Property with XX-Small Value
To set a xx-small size to the element's font, we use the xx-small value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .font { font-size: xx-small; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="font"> This text has a xx-small size. </p> </body> </html>
Font Size Property with X-Small Value
To set a x-small size to the element's font, we use the x-small value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .font { font-size: x-small; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="font"> This text has a x-small size. </p> </body> </html>
Font Size Property with Small Value
To set a small size to the element's font, we use the small value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .font { font-size: small; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="font"> This text has a small size. </p> </body> </html>
Font Size Property with Large Value
To set a large size to the element's font, we use the large value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .font { font-size: large; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="font"> This text has a large size. </p> </body> </html>
Font Size Property with X-Large Value
To set a x-large size to the element's font, we use the x-large value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .font { font-size: x-large; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="font"> This text has a x-large size. </p> </body> </html>
Font Size Property with XX-Large Value
To set a xx-large size to the element's font, we use the xx-large value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .font { font-size: xx-large; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="font"> This text has a xx-large size. </p> </body> </html>
Font Size Property with Smaller Value
To set a smaller size to the element's font, we use the smaller value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .font { font-size: smaller; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="font"> This text has a smaller size. </p> </body> </html>
Font Size Property with Larger Value
To set a larger size to the element's font, we use the larger value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .font { font-size: larger; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="font"> This text has a larger size. </p> </body> </html>
Font Size Property with Length Values
The font-size of an element can also be set using length values (e.g. px, rem, em etc.). This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .size1 { font-size: 2em; } .size2 { font-size: 25px; } .size3 { font-size: 3rem; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="size1"> This text has a 2em size. </p> <p class="size2"> This text has a 25px size. </p> <p class="size3"> This text has a 3rem size. </p> </body> </html>
Font Size Property with Percentage Values
The font-size of an element can also be set using percentage values (e.g. 10%, 4% etc.). This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .size1 { font-size: 120%; } .size2 { font-size: 140%; } </style> </head> <body> <h2> CSS font-size property </h2> <p> This is sample text. </p> <p class="size1"> This text has a 120% size. </p> <p class="size2"> This text has a 140% size. </p> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
font-size | 1.0 | 5.5 | 1.0 | 1.0 | 7.0 |