0% found this document useful (0 votes)
172 views13 pages

Text Decoration

The document discusses various CSS properties for styling text, including: - The text-decoration property for adding or removing underlines from links. - The text-transform property for changing text case to uppercase, lowercase, or capitalizing the first letter of each word. - Font properties like font-family, font-size, font-weight, and font-style for controlling typography. - Link styling properties like color, background-color, and text-decoration for styling links in different states like hover and active.

Uploaded by

Ady Bhau
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
172 views13 pages

Text Decoration

The document discusses various CSS properties for styling text, including: - The text-decoration property for adding or removing underlines from links. - The text-transform property for changing text case to uppercase, lowercase, or capitalizing the first letter of each word. - Font properties like font-family, font-size, font-weight, and font-style for controlling typography. - Link styling properties like color, background-color, and text-decoration for styling links in different states like hover and active.

Uploaded by

Ady Bhau
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Text Decoration

The text-decoration property is used to set or remove decorations from text.

The value text-decoration: none; is often used to remove underlines from


links:

Example
<!DOCTYPE html>

<html>

<head>

<style>

a{

text-decoration: none;

</style>

</head>

<body>

<p>A link with no underline: <a href="https://www.w3schools.com">W3Schools.com</a></p>

</body>

</html>

The other text-decoration values are used to decorate text:

<!DOCTYPE html>

<html>

<head>
<style>

h1 {

text-decoration: overline;

h2 {

text-decoration: line-through;

h3 {

text-decoration: underline;

</style>

</head>

<body>

<h1>This is heading 1</h1>

<h2>This is heading 2</h2>

<h3>This is heading 3</h3>

</body>

</html>

Text Transformation
The text-transform property is used to specify uppercase and lowercase
letters in a text.
It can be used to turn everything into uppercase or lowercase letters, or
capitalize the first letter of each word:

Example
p.uppercase {
text-transform: uppercase;
}

p.lowercase {
text-transform: lowercase;
}

p.capitalize {
text-transform: capitalize;
}

Text Indentation
The text-indent property is used to specify the indentation of the first line of a
text:

Example
p {
text-indent: 50px;
}

Letter Spacing
The letter-spacing property is used to specify the space between the
characters in a text.

The following example demonstrates how to increase or decrease the space


between characters:

Example
h1 {
letter-spacing: 3px;
}
h2 {
letter-spacing: -3px;
}
Try it Yourself »

Line Height
The line-height property is used to specify the space between lines:

Example
p.small {
line-height: 0.8;
}

p.big {
line-height: 1.8;
}
Try it Yourself »

Word Spacing
The word-spacing property is used to specify the space between the words in a
text.

The following example demonstrates how to increase or decrease the space


between words:

Example
h1 {
word-spacing: 10px;
}

h2 {
word-spacing: -5px;
}

Text Shadow
The text-shadow property adds shadow to text.
The following example specifies the position of the horizontal shadow (3px), the
position of the vertical shadow (2px) and the color of the shadow (red):

Example
h1 {
text-shadow: 3px 2px red;
}

Font Family
The font family of a text is set with the font-family property.

The font-family property should hold several font names as a "fallback"


system. If the browser does not support the first font, it tries the next font, and
so on.

Start with the font you want, and end with a generic family, to let the browser
pick a similar font in the generic family, if no other fonts are available.

Note: If the name of a font family is more than one word, it must be in
quotation marks, like: "Times New Roman".

More than one font family is specified in a comma-separated list:

Example
p {
font-family: "Times New Roman", Times, serif;
}
Try it Yourself »

Font Style
The font-style property is mostly used to specify italic text.

This property has three values:

 normal - The text is shown normally


 italic - The text is shown in italics
 oblique - The text is "leaning" (oblique is very similar to italic, but less
supported)
Example
p.normal {
font-style: normal;
}

p.italic {
font-style: italic;
}

p.oblique {
font-style: oblique;
}

Font Size
The font-size property sets the size of the text.

Being able to manage the text size is important in web design. However, you
should not use font size adjustments to make paragraphs look like headings, or
headings look like paragraphs.

Always use the proper HTML tags, like <h1> - <h6> for headings and <p> for
paragraphs.

The font-size value can be an absolute, or relative size.

Absolute size:

 Sets the text to a specified size


 Does not allow a user to change the text size in all browsers (bad for
accessibility reasons)
 Absolute size is useful when the physical size of the output is known

Relative size:

 Sets the size relative to surrounding elements


 Allows a user to change the text size in browsers

Note: If you do not specify a font size, the default size for normal text, like
paragraphs, is 16px (16px=1em).
Set Font Size With Pixels
Setting the text size with pixels gives you full control over the text size:

Example
h1 {
font-size: 40px;
}

h2 {
font-size: 30px;
}

p {
font-size: 14px;
}

Tip: If you use pixels, you can still use the zoom tool to resize the entire page.

Set Font Size With Em


To allow users to resize the text (in the browser menu), many developers use
em instead of pixels.

The em size unit is recommended by the W3C.

1em is equal to the current font size. The default text size in browsers is 16px.
So, the default size of 1em is 16px.

The size can be calculated from pixels to em using this formula: pixels/16=em

Example
h1 {
font-size: 2.5em; /* 40px/16=2.5em */
}

h2 {
font-size: 1.875em; /* 30px/16=1.875em */
}

p {
font-size: 0.875em; /* 14px/16=0.875em */
}

Try it Yourself »

Font Weight
The font-weight property specifies the weight of a font:

Example
p.normal {
font-weight: normal;
}

p.thick {
font-weight: bold;
}

Font Variant
The font-variant property specifies whether or not a text should be displayed
in a small-caps font.

In a small-caps font, all lowercase letters are converted to uppercase letters.


However, the converted uppercase letters appears in a smaller font size than
the original uppercase letters in the text.

Example
p.normal {
font-variant: normal;
}

p.small {
font-variant: small-caps;
}

Styling Links
Links can be styled with any CSS property (e.g. color, font-
family, background, etc.).

Example
a {
color: hotpink;
}

In addition, links can be styled differently depending on what state they are in.

The four links states are:

 a:link - a normal, unvisited link


 a:visited - a link the user has visited
 a:hover - a link when the user mouses over it
 a:active - a link the moment it is clicked

<!DOCTYPE html>

<html>

<head>

<style>

/* unvisited link */

a:link {

color: red;

/* visited link */

a:visited {

color: green;

/* mouse over link */


a:hover {

color: hotpink;

/* selected link */

a:active {

color: blue;

</style>

</head>

<body>

<p><b><a href="default.asp" target="_blank">This is a link</a></b></p>

<p><b>Note:</b> a:hover MUST come after a:link and a:visited in the CSS definition in order to be
effective.</p>

<p><b>Note:</b> a:active MUST come after a:hover in the CSS definition in order to be effective.</p>

</body>

</html>

Text Decoration
The text-decoration property is mostly used to remove underlines from links:

Example
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

a:active {
text-decoration: underline;
}

Background Color
The background-color property can be used to specify a background color for
links:

Example
a:link {
background-color: yellow;
}

a:visited {
background-color: cyan;
}

a:hover {
background-color: lightgreen;
}

a:active {
background-color: hotpink;
}

Advanced - Link Buttons


This example demonstrates a more advanced example where we combine
several CSS properties to display links as boxes/buttons:
<!DOCTYPE html>

<html>

<head>

<style>

a:link, a:visited {

background-color: #f44336;

color: white;

padding: 14px 25px;

text-align: center;

text-decoration: none;

display: inline-block;

a:hover, a:active {

background-color: red;

</style>

</head>

<body>

<a href="default.asp" target="_blank">This is a link</a>

</body>
</html>

You might also like