• Home
  • HTML
    • HTML Introduction
    • HTML Basic
    • HTML Elements
    • HTML Attributes
    • HTML Headings
    • HTML Paragraphs
    • HTML Text Formatting
    • HTML Styles
    • HTML Comments
    • HTML Styles - CSS
    • HTML Links
    • HTML Images
    • HTML Tables
    • HTML Lists
    • HTML Block and Inline Elements
    • HTML class Attribute
    • HTML Forms
    • HTML Media
  • CSS
    • Introduction of CSS
    • CSS Syntax
    • CSS Selectors
    • How To Add CSS
    • CSS Comments
    • CSS Colors
    • CSS Backgrounds
    • CSS Borders
    • CSS Margins
    • CSS Text
    • CSS Lists
    • CSS Tables
    • CSS Box Model
    • CSS Dimension
    • CSS Padding
    • CSS Border
    • CSS Margin
    • CSS Outline
    • CSS Cursors
    • CSS Overflow
    • CSS Units
    • CSS Visual Formatting
    • CSS Display
    • CSS Visibility
    • CSS Position
    • CSS Layers
    • CSS Float
    • CSS Alignment
    • CSS Pseudo-classes
    • CSS Pseudo-elements
    • CSS Media Types
    • CSS Sprites
    • CSS Opacity
    • CSS Attribute Selectors
    • CSS Validation
    • CSS3 Border
    • CSS3 Gradients
    • CSS3 Text Overflow
  • JavaScript
    • JS Introduction
    • JS Getting Started
    • JS Syntax
    • JS Variables
    • JS Generating Output
    • JS Data Types
    • JS Operators
    • JS Events
    • JS Strings
    • JS Numbers
    • JS If Else
    • JS Switch Case
    • JS Arrays
    • JS Sorting Arrays
    • JS Loops
    • JS Functions
    • JS Objects
    • JS DOM Nodes
    • JS DOM Selectors
    • JS DOM Styling
    • JS DOM Get Set Attributes
    • JS DOM Manipulation
    • JS DOM Navigation
    • JS Window
    • JS Screen
    • JS Location
    • JS History
    • JS Navigator
    • JS Dialog Boxes
    • JS Timers
    • JS Date and Time
    • JS Math Operations
    • JS Type Conversions
    • JS Event Listeners
    • JS Event Propagation
    • JS Borrowing Methods
    • JS Hoisting Behavior
    • JS Closures
    • JS Strict Mode
    • JS JSON Parsing
    • JS Error Handling
    • JS Regular Expressions
    • JS Form Validation
    • JS Cookies
    • JS AJAX Requests
    • JS ES6 Features
  • jQuery
    • jQuery Introduction
    • jQuery Syntax
    • jQuery Selectors
    • jQuery Events
    • jQuery Show/Hide
    • jQuery Fade
    • jQuery Slide
    • jQuery Animation
    • jQuery Stop
    • jQuery Chaining
    • jQuery Callback
    • jQuery Get/Set
    • jQuery Insert
    • jQuery Remove
    • jQuery CSS Classes
    • jQuery Style Properties
    • jQuery Dimensions
    • jQuery Traversing
    • jQuery Ancestors
    • jQuery Descendants
    • jQuery Siblings
    • jQuery Filtering
    • jQuery Ajax
    • jQuery Load
    • jQuery Get/Post
    • jQuery No-Conflict
  • PHP
    • PHP Introduction
    • PHP Install
    • PHP Syntax
    • PHP Comments
    • PHP Variables
    • PHP Echo / Print
    • PHP Data Types
    • PHP Strings
    • PHP Constants
    • PHP Operators
    • PHP If...Else...Elseif
    • PHP Switch
    • PHP Loops
    • PHP Functions
    • PHP Arrays
    • PHP Superglobals
    • PHP Date and Time
    • PHP Include
    • PHP File Handling
    • PHP File Upload
    • PHP Cookies
    • PHP Sessions
    • PHP Filters
    • PHP Callback Functions
    • PHP JSON
    • PHP Exceptions
    • PHP What is OOP
    • PHP Classes/Objects
    • PHP Constructor
    • PHP Destructor
    • PHP Access Modifiers
    • PHP Inheritance
    • PHP Abstract Classes
    • PHP Interfaces
    • PHP Traits
    • PHP Static Methods
    • PHP Namespaces
  • SQL
    • Introduction to SQL
    • SQL Create Command
    • SQL ALTER Command
    • SQL Truncate Drop Rename
    • INSERT SQL command
    • UPDATE SQL command
    • DELETE SQL command
    • SQL COMMIT command
    • SQL ROLLBACK command
    • SQL GRANT and REVOKE Command
    • SQL WHERE clause
    • SQL LIKE clause
    • SQL ORDER BY Clause
    • SQL Group By Clause
    • SQL HAVING Clause
    • SQL DISTINCT keyword
    • SQL AND OR operator
    • SQL Constraints
    • SQL Functions
    • SQL JOIN
  • Python
    • Getting started with Python
    • Introduction to IDLE
    • Python 2.x vs. Python 3.x
    • Syntax Rules and First Program
    • Numbers and Math Functions
    • Python Operators
    • Python Variables
    • Python Modules and Functions
    • Python Input and Output
    • Data Types in Python
    • String in Python
    • String Functions in python
    • Lists in Python
    • Utilizing List Elements by Iterating
    • Deleting List Elements & other Functions
    • Dictionaries in Python
    • Functions for Dictionary
    • Tuples in Python
    • Relational and Logical Operators
    • Conditional Statements in Python
    • Looping in Python
    • Define Functions in Python
    • Python-Introduction to OOP
    • Object Oriented Programming in Python
    • Classes in Python
    • The concept of Constructor
    • Destructors - Destroying the Object in Python
    • Inheritance in Python
    • Access Modifers in Python
    • Types of Inheritance
    • Method Overriding in Python
    • Polymorphism
    • static Keyword
    • Operator Overloading Python
    • Introduction to Error Handling
    • Exception Handling: try and except
    • Exeption Handling: finally
    • Exception Handling: raise
    • File Handling
    • Reading and Writing File
    • Introduction to Multithreading
    • Threading Module in Python
    • Thread Object
    • Lock Object
    • RLock Object
    • Event Object
    • Timer Object
    • Condition Object
    • Barrier Object
    • __name__ Variable in Python
    • Iterable and Iterator
    • yield Keyword
    • Python Generators
    • Python Closures
    • Python Decorators
    • @property Decorator in Python
    • Assert Statement
    • Garbage Collection
    • Shallow and Deep Copy
    • Introduction to Logging
    • Configure Log LEVEL, Format etc
    • Python Logging in a file
    • Python Logging Variable Data
    • Python Logging Classes and Functions
    • Python MySQL Introduction
    • Create Database - Python MySQL
    • Create Table - Python MySQL
    • Insert Data in Table
    • Select Data from Table
    • Update data in Table
    • Delete data from Table
    • Drop Table from Database
    • WHERE clause - Python MySQL
    • Order By clause - Python MySQL
    • Limit clause - Python MySQL
    • Table Joins - Python MySQL
  • MongoDB
    • MongoDB Introduction
    • Overview of MongoDB
    • MongoDB vs SQL Databases
    • Advantages of MongoDB
    • When to go for MongoDB
    • Data Modelling in MongoDB
    • Is MongoDB really Schemaless?
    • Installing MongoDB on Windows and Linux
    • Datatypes in MongoDB
    • Create and Drop Database in MongoDB
    • MongoDB: Creating a Collection
    • CRUD Operations in MongoDB
    • Data Relationships in MongoDB
    • Indexing in MongoDB
    • Sorting in MongoDB
    • Aggregation in MongoDB
    • Data Backup and Restoration in MongoDB
    • Sharding in MongoDB
    • Java Integration with MongoDB
  • Elixir
    • Elixir Overview
    • Elixir Environment
    • Elixir Basic Syntax
    • Elixir Data Types
    • Elixir Variables
    • Elixir Operators
    • Elixir Pattern Matching
    • Elixir Decision Making
    • Elixir Strings
    • Elixir Char Lists
    • Elixir Lists and Tuples
    • Elixir Keyword Lists
    • Elixir Maps
    • Elixir Modules
    • Elixir Aliases
    • Elixir Functions
    • Elixir Recursion
    • Elixir Loops
    • Elixir Enumerables
    • Elixir Streams
    • Elixir Structs
    • Elixir Protocols
    • Elixir File I/O
    • Elixir Processes
    • Elixir Sigils
    • Elixir Comprehensions
    • Elixir Typespecs
    • Elixir Behaviours
    • Elixir Errors Handling
    • Elixir Macros
    • Elixir Libraries
  • TypeScript
    • TypeScript Overview
    • Install TypeScript
    • First TypeScript Program
    • Type Annotation
    • TypeScript Variable
    • TypeScript Data Type Number
    • TypeScript Data Type String
    • TypeScript Data Type Boolean
    • TypeScript Arrays
    • TypeScript Tuples
    • TypeScript Enum
    • TypeScript Union
    • TypeScript Any Data Type
    • TypeScript Void Data Type
    • TypeScript Never Data Type
  • Home
  • Introduction of CSS
  • CSS Syntax
  • CSS Selectors
  • How To Add CSS
  • CSS Comments
  • CSS Colors
  • CSS Backgrounds
  • CSS Borders
  • CSS Margins
  • CSS Text
  • CSS Lists
  • CSS Tables
  • CSS Box Model
  • CSS Dimension
  • CSS Padding
  • CSS Border
  • CSS Margin
  • CSS Outline
  • CSS Cursors
  • CSS Overflow
  • CSS Units
  • CSS Visual Formatting
  • CSS Display
  • CSS Visibility
  • CSS Position
  • CSS Layers
  • CSS Float
  • CSS Alignment
  • CSS Pseudo-classes
  • CSS Pseudo-elements
  • CSS Media Types
  • CSS Sprites
  • CSS Opacity
  • CSS Attribute Selectors
  • CSS Validation
  • CSS3 Border
  • CSS3 Gradients
  • CSS3 Text Overflow
Home >> css >> CSS Text

CSS Text

This tutorial helps you learn how to style text on your web pages using CSS.

 

Formatting Text with CSS

There are several properties in CSS that allows you to define various text styles like alignment, color, spacing, transformation, decoration, etc., very easily and effectively.

Text properties that are commonly used are text-transform, text-decoration, text-align, text-indent, letter-spacing, line-height, word-spacing, etc. With these properties, you can get precise control over the visual appearance of the characters, spaces, words, etc.

Let's see how you can set these text properties for an element

 

Text Color

The CSS color property defines the color of the text.

The style rule in the example here will define the page's default text color.

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
body {
    color: #434343;
}
  </style>
</head>
<body>
           <div>
             <h1>Welcome to CSS Tutorial</h1>
             <p>I am a CSS Developer!</p>
          </div>
           
</body>
</html>

Try With Example

Though the color property seems to be a part of the CSS text, on the contrary, it is a standalone property in CSS. You can refer to the tutorial on CSS color to know more about the color property.

 

Text Alignment

You can use the text-align property to set the text's horizontal alignment.

You can align the text in four ways: to the right, left, centre, or justified (straight left and right margins).

The example will help you understand how this property works.

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
h1 {
    text-align: center;
}
p {
    text-align: justify;
}
  </style>
</head>
<body>
           <div>
             <h1>Welcome to CSS Tutorial</h1>
             <p>I am a CSS Developer!</p>
          </div>
           
</body>
</html>

Try With Example

Let's look at the following example to see what these values actually mean.

Text Decoration

You can use the text-decoration property for setting or removing decorations from a text.

The text-decoration property usually accepts one of the following values: overline, underline, line-through, and none. It is recommended to avoid underlining text that is not a link, as it may confuse a visitor.

Let's consider the example below to understand how it basically works:

Example :

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
h1 {
    text-decoration: overline;
}
h2 {
    text-decoration: line-through;
}
h3 {
    text-decoration: underline;
}
  </style>
</head>
<body>
           <div>
             <h1>Welcome to CSS Tutorial</h1>
             <h2>I am a CSS Developer!</h2>
             <h3>Reading CSS Text styling</h3>
          </div>
           
</body>
</html>

Try With Example

 

Removing the Default Underline from Links

The most extensive use of the text-decoration property is for removing the default underline from the HTML hyperlinks. However, some other visual cues can be further provided for making it stand out from the normal text. For illustration, use of dotted border rather than a solid underline.

Let's consider the example below to understand how it basically works:

Example:

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
a{
    text-decoration: none;
    border-bottom: 1px dotted;
}
  </style>
</head>
<body>
           <div>
             <a href="http://readytocode.net/" target="_BLANK">Read Our Blog</a>
             <h2>I am a CSS Developer!</h2>
             <h3>Reading CSS Text styling</h3>
          </div>
           
</body>
</html>

Try With Example

Note: On creating an HTML link, the built-in style sheet of the browser automatically underlines it and applies blue color to it, so readers can know which text is clickable.

 

Text Transformation

You can use the text-transform property to set the cases for a text.

Text is often written in mixed cases. However, you may want to display your text in an entirely different case in certain situations. You can use this property to change an element's text content into uppercase or lowercase letters or for capitalizing each word's first letter without modifying the original text.

The example below helps you to understand how it basically works:

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
h1 {
    text-transform: uppercase;
}
h2 {
    text-transform: capitalize;
}
h3 {
    text-transform: lowercase;
}
  </style>
</head>
<body>
           <div>
             <h1>Welcome to CSS Tutorial</h1>
             <h2>I am a CSS Developer!</h2>
             <h3>Reading CSS Text styling</h3>
          </div>
           
</body>
</html>

Try With Example

 

Text Indentation

You can use the text-indent property to set the indentation of the first line of text within a text block.

To do this, insert an empty space before the text's first line. You can specify the indentation size using percentage (%), length values in ems, pixels, etc.

The style rule mentioned below will indent the paragraphs' first line by 100 pixels.

Example :

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
p {
    text-indent: 100px;
}
  </style>
</head>
<body>
           <div>
             <p>You can use the text-indent property to set the indentation of the first line of text within a text block.

To do this, insert an empty space before the text's first line. You can specify the indentation size using percentage (%), length values in ems, pixels, etc.</p>

            
          </div>
           
</body>
</html>

Try With Example

Note: Whether the text will be indented from the left or the right is dependent on the text's direction inside the element, specified by the CSS direction property.

 

Letter Spacing

You can use the letter-spacing property for setting extra spacing between the text's characters.

You can define the length value for this property in ems, pixels, etc. Negative values are also accepted by this property. When you set the letter spacing, a length value implies spacing in addition to the default inter-character space.

The example below helps you to understand how it works:

Example :

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
h1 {
    letter-spacing: -3px;
}
p {
    letter-spacing: 10px;
}
  </style>
</head>
<body>
           <div>
<h1>CSS Letter Spacing Example</h1>
             <p>You can use the text-indent property to set the indentation of the first line of text within a text block.

To do this, insert an empty space before the text's first line. You can specify the indentation size using percentage (%), length values in ems, pixels, etc.</p>

            
          </div>
           
</body>
</html>

Try With Example

 

Word Spacing

You can use the word-spacing property for specifying the additional spacing between the words.

The word-spacing property can accept a length value in ems, pixels, etc. You can also specify negative values.

The example below helps you to understand how this property works:

Example:

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
p.normal {
    word-spacing: 20px;
}
p.justified {
    word-spacing: 20px;
    text-align: justify;
}
p.preformatted {
    word-spacing: 20px;
    white-space: pre;
}
  </style>
</head>
<body>
           <div>
<h1>CSS Letter Spacing Example</h1>
             <p class="normal">You can use the text-indent property to set the indentation of the first line of text within a text block.

To do this, insert an empty space before the text's first line. You can specify the indentation size using percentage (%), length values in ems, pixels, etc.</p>

<p class="justified">You can use the text-indent property to set the indentation of the first line of text within a text block.

To do this, insert an empty space before the text's first line. You can specify the indentation size using percentage (%), length values in ems, pixels, etc.</p>

<p class="preformatted">You can use the text-indent property to set the indentation of the first line of text within a text block.

To do this, insert an empty space before the text's first line. You can specify the indentation size using percentage (%), length values in ems, pixels, etc.</p>

            
          </div>
           
</body>
</html>

Try With Example

Note: Text justification affects the word spacing. Although whitespace is preserved, the word-spacing property affects the spaces between words.

 

Line Height

You can use the line-height property for setting the text line's height.

It is also known as leading and is generally used for setting the distance between text lines.

The line-height property's value can be a number, a length in pixels, ems, or a percentage (%), etc.

Example :

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
p {
    line-height: 1.2;
}
  </style>
</head>
<body>
           <div>
<h1>CSS Line Height Example</h1>
             <p>You can use the text-indent property to set the indentation of the first line of text within a text block.

To do this, insert an empty space before the text's first line. You can specify the indentation size using percentage (%), length values in ems, pixels, etc.</p>

            
          </div>
           
</body>
</html>

Try With Example

If the value is specified in a number, the element's font size is multiplied by the number to calculate the line-height. In contrast, values in percentage are relative to the font size of the element.

Note: Negative values cannot be specified for the line-height property. The line-height property is also the CSS font shorthand property's component.

 

If the line-height property's value is greater than the element's font-size value, then the difference (called the "leading") is divided in half (called the "half-leading") and distributed evenly on the top and bottom of the in-line box. Let's see an example:

<!DOCTYPE html>
<html>
<head>
           <title>CSS Text</title>
<style>
p {
    font-size: 14px;
    line-height: 20px;
    background-color: #f0e68c;
}
  </style>
</head>
<body>
           <div>
<h1>CSS Line Height Example</h1>
             <p>You can use the text-indent property to set the indentation of the first line of text within a text block.

To do this, insert an empty space before the text's first line. You can specify the indentation size using percentage (%), length values in ems, pixels, etc.</p>

            
          </div>
           
</body>
</html>

Try With Example

  • Prev
  • Next


-Advertisement-


DeveloperTutorial
[email protected] © 2022-2023 Developers Tutorial All rights reserved.

Follow Us

Facebook Twitter LinkedIn Printerest Reddit

Announcement

Its a big achivement for us, We make a partnership with TutorialWithExample.com for the better content of our users.

Still Need Help ?

Let us now about your issue and a Professional will reach you out.