html span

Just like <div> is used to group a block of content, <span> is used to group a piece of text inside a line. The name stands for “span.” 

<p>

  She became widely known for performances in 

  <span>Lost in Translation</span> and 

  <span>Girl with a Pearl Earring</span>.

</p>

Just this will look same, lets add little CSS. 

<style>

  span {

    background-color: lightblue;

  }

</style>

Output

Now only the movie names inside <span> will show with a light blue background.

That’s all — <span> lets you mark and style small pieces of text.


Assignment

In the section 1994–2002: Early work and breakthrough, you will find this line:

She appeared in several films as a child actress and gained attention with The Horse Whisperer.

Your task:

Wrap the words The Horse Whisperer in a <span>.

Change the <span> background color to purple using CSS.

When done, only The Horse Whisperer should appear with a purple background.

Expected Output


Solution 

<h3>1994–2002: Early work and breakthrough</h3>

<p>

  She appeared in several films as a child actress and gained attention with 

  <span>The Horse Whisperer</span>.

</p>

<style>

  span {

    background-color: purple;

  }

</style>

⬅️ Previous Lesson  Next Lesson ➡️

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top