×

CSS Font

CSS Font: CSS has font property, which makes the text more attractive. We can alter the entire look by changing font color, font size, font style, and much more. In this section, we will learn how to change the size of our font by the use percentage. The following are a few critical attributes which we can use in our text to make it more attractive:

Attributes Description
Font color Font color property is applied to modify the text color.
Font size Font size property is applied to either increase the font size or decrease the font size.
Font family Font family property is applied to modify the font face.
Font style Font style property is applied to produce the font oblique, italic, or bold.
Font weight Font weight property is applied to increase the font’s lightness and boldness or decrease the same.
Font variant The font-variant is applied to makes an effect of small-caps.

Font Color

The font color property of CSS is a unique and standalone attribute, although it looks like a type of fonts in CSS. It is applied to make modifications to the text color. We can define the font color by one of the following formats:

  • Color name
  • Hexadecimal value
  • RGB

Example:

<!DOCTYPE html>
 <html>
 <head>
 <style>
 body {
 font-size: 100%; 
 } 
 h1 {color: green;} 
 h2 {color: #FF00FF;}  /*Fuchsia Color*/
 p {color: rgb(0, 255, 255);}   /*Aqua Color*/
 </style>
 </head> 
 <body>
 <h1>This is First Heading.</h1>
 <h2>This is second Heading.</h2>
 <p>This is paragraph.</p>
 </body>
 </html>  

Output:

CSS Font

Font Size

The font size attribute of CSS is applied to modify the font size. Some of the essential values that are applied to set-up the size of the font:

  • xx-small:  It isapplied to show the text in extremely small size.
  • x-small: It isapplied to show the text in extra small size.
  • small: It isapplied to show the text in small size.
  • medium: It isapplied to show the text in medium size.
  • large: It isapplied to show the text in large size.
  • x-large: It isapplied to show the text in extra-large size.
  • xx-large: It isapplied to explain the text in extremely large size.
  • smaller: It isapplied to show the text comparatively in smaller size.
  • larger: It isappliedto show the text comparatively in larger size.
  • % or pixels size: It isemployed to set the font size in percentage or in pixels.

Example:

<!DOCTYPE html>
 <html>
 <head>
 </head>
 <body>
 <p style="font-size:xx-small;">These fonts are in extremely small size.</p> 
 <p style="font-size:x-small;">These fonts are in extra small size.</p>
 <p style="font-size:small;">These fonts are in small size.</p>
 <p style="font-size:medium;">These fonts are in medium size.</p>
 <p style="font-size:large;">These fonts are in large size.</p>
 <p style="font-size:x-large;">These fonts are in extra large size.</p> 
 <p style="font-size:xx-large;">These fonts are in extremely large size.</p>
 <p style="font-size:smaller;">These fonts are in smaller size.</p>
 <p style="font-size:larger;">These fonts are in larger size.</p>
 <p style="font-size:100%;">These fonts are in 100% size.</p> 
 <p style="font-size:30px;">These fonts are in 30pixel size.</p>
 </body>
 </html>  

Output:

CSS Font

Font Family

The font family is categorized into two parts:

  • Font family: It defines the name of the font family such as Times New Roman, Arial etc.
  • Generic family: The generic family includes Sans-serif, Monospace, and Serif.

Serif: These types of fonts incorporate tiny lines at any character’s end. Its examples are- Georgia, and Times New Roman.

Sans-serif: It does not hold tiny lines at any character end. The examples are- Verdana, Arial, etc.

Monospace: Every character of monospace has the similar width.

Example:

<!DOCTYPE html>
 <html>
 <head>
 <style>
 .sansserif { 
 font-family: sans-serif;
 }
 .serif {
 font-family: serif;
 }
 .monospace {
 font-family: monospace; 
 } 
 </style>
 </head>
 <body>
 <h1 class="sansserif">These fonts are in sans-serif.</h1>
 <h2 class="serif">These fonts are in serif.</h2>
 <p class="monospace">These fonts are in monospace.</p> 
 </body>
 </html> 

Output:

CSS Font

Font Style

This property describes what kind of font view we wish to illustrate on the screen. These styles can be normal, italic, oblique etc.

Example:

<!DOCTYPE html>
 <html>
 <head>
 <style> 
 .italic {
 font-style: italic;
 }
 .oblique {
 font-style: oblique;
 } 
 .normal {
 font-style: normal;
 }
 </style>
 </head>
 <body>
 <h1 class="italic">These fonts are in italic style.</h1> 
 <h2 class="oblique">These fonts are in oblique style.</h2>
 <p class="normal">These fonts are in normal style.</p>
 </body>
 </html> 

Output:

CSS Font

Font Weight

It is used to depict the weight of the font. Some of the values to determine the font’s weight are- bold, bolder, lighter, normal, number, or lighter.

Example:

<!DOCTYPE html>
 <html>
 <head>
 </head>
 <body>
 <p style="font-weight:bold;">These fonts are bold.</p> 
 <p style="font-weight:bolder;">These fonts are bolder.</p>
 <p style="font-weight:lighter;">These fonts are lighter.</p>
 <p style="font-weight:100;">These fonts have 100 weight.</p>
 <p style="font-weight:200;">These fonts have 200 weight.</p> 
 <p style="font-weight:300;">These fonts have 300 weight.</p>
 <p style="font-weight:400;">These fonts have 400 weight.</p>
 <p style="font-weight:500;">These fonts have 500 weight.</p>
 <p style="font-weight:600;">These fonts have 600 weight.</p>
 <p style="font-weight:700;">These fonts have 700 weight.</p>
 <p style="font-weight:800;">These fonts have 800 weight.</p>
 </body>      
 </html>  

Output:

CSS Font

Font Variant

It determines that either the text should be viewed in the small-caps font effect. The effect can also be set as normal.

Example:

<!DOCTYPE html>
 <html>
 <head>
 <style>
 .smallcaps {
 font-variant: small-caps; 
 } 
 .normal {
 font-variant: normal;
 }
 </style>
 </head> 
 <body>
 <p class="smallcaps">These fonts are in small-caps variant.</p>
 <p class="normal">These fonts are in normal variant.</p>
 </body>
 </html>  

Output:

CSS Font

Related Topics

CSS Color Keywords

Here, we will discuss the following keywords: transparent currentcolor Inherit Transparent keyword A color can generally be made transparent by using the transparent keyword. Often it is used to for all intents...

4 minutes read.

How to center a button in CSS

How to center a button in CSS? In the tutorial, we will learn how to center a button in CSS. CSS (Cascading Style Sheets) gives an HTML web page the greatest possible...

4 minutes read.

CSS Word-spacing

Word-spacing The work-spacing property of CSS is applied to manage the space among the words. We can decrease or increase the space among the words by the use of this property. It...

3 minutes read.

CSS Browser Support

The desk underneath lists of all CSS properties and the way each belongs to it is supported in the generally unique browsers: - The quantity to the right of the browser...

2 minutes read.

CSS 3D Transform

Introduction To understand 3D transformation property of transform you need to first understand the difference between 2D and 3D transform. 2D transform is a CSS effect which transforms the elements according to...

6 minutes read.

Grid Vs Flexbox in CSS

Grid: - CSS Grid Layout is a 2D grid-based matrix-based layout method with columns and rows that simplifies web pages created by eliminating the need for floats and placement. A grid layout, like...

4 minutes read.

CSS Table

CSS table provides better look and feel. There are various properties of CSS table that are given below. border border-collapse padding width height text-align color background-color CSS Table Border You can set...

4 minutes read.

CSS Functions

CSS functions are used for different CSS properties. Every front-end developer should have knowledge of all CSS functions. It makes the coding easier. FunctionsExplanationattr().It returns the value of an attribute of...

5 minutes read.

How to make smooth bounce animation using CSS

The smooth bouncing animation project is done with the help of HTML and CSS. This project gives so much fun and excitement to the users. What is HTML? The HTML or HyperText...

2 minutes read.

CSS Tutorial

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

9 minutes read.

CSS Arrow

CSS Arrow The arrow of CSS is applied to insert an array with the tooltip. It can make a tooltip as any speech bubble. Also, this arrow can be illustrated in...

4 minutes read.

Create a 3D text effect using HTML and CSS

A3D text effect is a beautiful and attractive part of a webpage. As a web page developer, it is crucial to know how to create a 3D text effect with...

3 minutes read.

CSS Text-Overflow

Introduction: The text-overflow property of CSS is used to format the text which is overflowing the boundaries of the container. This property helps user to clip the text, to display the...

5 minutes read.

CSS Text Effects

Text Effects in CSS We can use distinct text effects used inside the HTML document. Few attributes can be applied to insert the text effects. We can also style various web documents...

5 minutes read.

CSS Sticky

CSS Sticky The position property in CSS is applied to set an element’s position. This property is also applied to position an element behind the other element. It is useful for...

1 minute read.

CSS Lists

CSS Lists: Several properties are available in CSS that are used to manage the lists. Lists are distributed as ordered and unordered kind of lists. The ordered lists provide the...

7 minutes read.

CSS Vertical Align

Vertical Align The vertical align CSS property describes the cell box of the table and an inline alignment vertically. This property is a self-explanatory and an essential property in CSS. But,...

2 minutes read.

CSS Dropdowns

Dropdowns are one of the maximum crucial parts of an interactive internet site. CSS is a kind used to design the drop-down menus. A drop-down essentially is a group of...

5 minutes read.

Internal CSS

What is CSS? CSS stands for Cascading Style Sheet.CSS is used to apply styling the HTML elements.With CSS user can add or change color, font-size and font-family. It also helps user...

4 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.