Open In App

HTMLText Styling Exercises - 2024

Last Updated : 15 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

HTML text styling is a foundational skill in web development, essential for creating visually appealing and readable content. From basic font changes to advanced CSS effects, these exercises will guide you through various methods to style text in HTML.

Let's explore over 30+ exercises, progressing from beginner-friendly techniques to more advanced styling methods.

1. How to Make Text Bold in HTML?

To add text in bold in HTML, the <b> and <strong> tags are used.

HTML Code:

<p>
<b>Bold Text</b>
or <strong>Important Text</strong>
</p>

CSS Code:

b, strong { 
font-weight: bold;
}

2. How to Italicize Text in HTML?

To italicize text in HTML, the <i> and <em> tags are used.

HTML Code:

<p>
<i>Italic Text</i>
or
<em>Emphasized Text</em>
</p>

3. Which tag should you use to emphasize a word?

To emphasize a word in HTML, the <em> tag should be used.

HTML Code:

<p>This is an <em>important</em> word!</p>

4. How to create different heading levels in HTML?

To create different heading levels in HTML, the <h1>, <h2>, <h3>, <h4>, <h5>, and <h6> tags are used.

HTML Code:

<h1>This is a big heading!</h1>
<h2>This is a smaller heading!</h2>

5. Which tag is used add a line break within a paragraph?

The <br> is used to add a line break within a paragraph in HTML.

HTML Code:

<p>This is the first line.<br>This is the second line.</p>

6. Why we use the <strong> tag instead of <b>?

The <strong> tag makes text important and bold, while <b> just makes it bold.

7. How to center-align text in HTML?

To center-align text in HTML, use the <div> or <p> tag with the style attribute.

HTML Code:

<p style="text-align: center;">This text is centered!</p>

8. What is the difference between ordered and unordered lists?

An ordered list are the list which uses numbers, like 1, 2, 3, while an unordered list uses dots or bullets. Use <ol> for ordered and <ul> for unordered lists.

HTML Code:

<ol>
<li>First item</li>
<li>Second item</li>
</ol>
<ul>
<li>First item</li>
<li>Second item</li>
</ul>

9. How to change the text color using inline CSS?

To change the text color using inline CSS, use the style property

HTML Code:

<p style="color: blue;">This text is blue!</p>

10. What property controls font size in HTML?

The font size in CSS is used to change the size of the text.

HTML Code:

<p style="font-size: 20px;">This text is big!</p>

11. How to underline text in CSS?

To underline text in CSS, use the text-decoration property with the value underline.

HTML Code :

<p style="text-decoration: underline;">This text is underlined!</p>

12. Why you use the font-family property in text?

The font-family property is used to change the font of text in HTML.

HTML Code :

<p style="font-family: Arial;">This text uses Arial font!</p>

13. How can you make text uppercase with CSS?

To make text uppercase with CSS, use the text-transform property with the value uppercase.

HTML Code:

<p style="text-transform: uppercase;">This text is now uppercase!</p>

14. Which property would you use to capitalize the first letter of each word?

To capitalize the first letter of each word, use the text-transform property with the value capitalize.

HTML Code:

<p style="text-transform: capitalize;">this text has capitalized words.</p>

15. How can you indent the first line of a paragraph in CSS?

To indent the first line of a paragraph in CSS, use the text-indent property.

HTML Code:

<p style="text-indent: 20px;">This first line is indented!</p>

16. How to Create Text with a 3D Shadow Effect?

To create text with a 3D shadow effect in CSS, use the text-shadow property with multiple shadow values.

HTML Code:

<h2 class="shadow3d-text">3D Shadow Text</h2>

CSS Code:

.shadow3d-text {  
color: black;
text-shadow: 2px 2px 0px gray, 4px 4px 0px lightgray;
}

17. What is Font-Weight Property in CSS?

The font-weight property in CSS controls the thickness or boldness of text.

HTML Code:

<p class="bold-text">This is bold text!</p>

CSS Code:

.bold-text {
font-weight: bold;
}

18. How Can Line Height Improve Text Readability?

The line-height property in CSS increases the space between lines of text, making it easier to read.

HTML Code:

<p class="spaced-paragraph">This is a paragraph with better spacing!</p>

CSS Code:

.spaced-paragraph {
line-height: 1.5;
}

19. Which CSS Property is Used to Add Space Between Letters?

The letter-spacing property in CSS is used to add space between letters.

HTML Code:

<p class="spaced-letters">This text has spaced-out letters!</p>

CSS Code:

.spaced-letters {
letter-spacing: 2px;
}

20. How Responsive Text Resizing Work with Viewport Units (vw, vh)?

Responsive text resizing with viewport units (vw, vh) adjusts the text size based on the viewport's width (vw) or height (vh).

HTML Code:

<p class="responsive-text">This text size changes with the screen!</p>

CSS Code:

.responsive-text {
font-size: 5vw;
}

21. What’s the Benefit of Using Google Fonts in an HTML Document?

The benefit of using Google Fonts in an HTML document is that it allows you to easily use a wide variety of custom fonts in our HTML Document.

HTML Code:

<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<p class="google-font">This text uses a Google Font!</p>

CSS Code:

.google-font {
font-family: 'Roboto', sans-serif;
}

22. How Can You Apply Multiple Text Decorations (e.g., Underline and Overline)?

You can apply multiple text decorations in CSS by using the text-decoration property with a space-separated list of values.

HTML Code:

<p class="decorated-text">This text is underlined and overlined!</p>

CSS Code:

.decorated-text {
text-decoration: underline overline;
}

23. Which Tags Are Used to Display a Line of Code Properly in HTML?

The <code> tag is used to display a line of code properly in HTML.

HTML Code:

<code>console.log("Hello World!");</code>

24. How to Add a Gradient Effect to Text with CSS?

To add a gradient effect to text with CSS by using the background-image property along with -webkit-background-clip.

HTML Code:

<h1 class="gradient-text">Colorful Gradient Text</h1>

CSS Code:

.gradient-text {
background: linear-gradient(to right, red, blue);
-webkit-background-clip: text;
color: transparent;
}

25. What’s the Purpose of the Text-Overflow Property?

The text-overflow property in CSS is used to control how text is displayed when it overflows its container, tyy by adding ellipsis (...) or clipping the text.

HTML Code:

<div class="overflow-text">This is some really long text that will not fit!</div>

CSS Code:

.overflow-text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

26. How CSS Variables Simplify Text Styling in a Document?

CSS variables simplify text styling by allowing you to define a value once and reuse it multiple times throughout the document.

HTML Code:

<p class="variable-text">This text uses a CSS variable for color!</p>

CSS Code:

:root {
--main-color: blue;
}
.variable-text {
color: var(--main-color);
}

27. How You Create a Responsive Font Size That Changes with Screen Width?

To create a responsive font size that changes with screen width, use the vw (viewport width) unit.

HTML Code:

<p class="responsive-font-size">This text size changes with the screen width!</p>

CSS Code:

.responsive-font-size {
font-size: 3vw;
}

28. How to Add Strikethrough Text in HTML?

To add strikethrough text in HTML, use the <s> or <strike> tag.

HTML Code:

<p>This is <s>struck out</s> text!</p>

29. How to Use Custom Fonts in HTML?

To use custom fonts in HTML, link to a font from a service like Google Fonts or import a font file.

HTML Code:

<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<p class="custom-font">This text uses a custom font!</p>

CSS Code:

.custom-font {
font-family: 'Open Sans', sans-serif;
}

30. How to Create Text with Typing Animation Effect?

To create text with a typing animation effect in CSS, use @keyframes to animate the width and overflow properties.

HTML Code:

<div id="typing"></div>

JavaScript Code:

const text = "Hello, welcome to my website!";
let i = 0;

function type() {
if (i < text.length) {
document.getElementById("typing").innerHTML += text.charAt(i);
i++;
setTimeout(type, 100);
}
}

type();

31. How to Create Text with Neon Glow Effect?

To create text with a neon glow effect in CSS, use the text-shadow property with multiple shadow values.

HTML Code:

<h1 class="neon-text">Neon Glow Text!</h1>

CSS Code:

.neon-text {
color: #fff;
text-shadow: 0 0 5px #fff, 0 0 10px #0ff, 0 0 20px #0ff, 0 0 40px #0ff;
}

32. How to Create Transparent Text with an Image Background?

To create transparent text with an image background, use the background-image property along with the background-clip property.

HTML Code:

<h1 class="transparent-text">Transparent Text!</h1>

CSS Code:

.transparent-text {
font-size: 60px;
color: transparent;
background: url('your-image.jpg') no-repeat;
-webkit-background-clip: text;
background-clip: text;
}

33. How to Animate Text Color on Hover?

To animate the text color on hover, use the transition property along with the :hover pseudo-class.

HTML Code:

<p class="hover-text">Hover over me!</p>

CSS Code:

.hover-text {
color: blue;
transition: color 0.5s;
}

.hover-text:hover {
color: red;
}

34. How to Create a Bouncing Text Animation?

To create a bouncing text animation, use the @keyframes rule to animate the transform property with translateY.

HTML Code:

<h2 class="bounce-text">Bouncing Text!</h2>

CSS Code:

.bounce-text {
display: inline-block;
animation: bounce 1s infinite;
}

@keyframes bounce {
0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
40% { transform: translateY(-20px); }
}

35. How to Create a Text-Reveal Effect Using HTML and CSS?

To create a text-reveal effect, use @keyframes rule to animate the width or clip-path of the text, making it appear progressively.

HTML Code:

<div class="reveal-text">Hover to reveal the secret text!</div>

CSS Code:

.reveal-text {
color: transparent;
background-color: black;
transition: color 0.5s;
}
.reveal-text:hover {
color: white;
}

Article Tags :

Similar Reads