Articles → HTML → Span Tag In HTML

Span Tag In HTML






What Is An Inline Element?






Picture showing the horizontal space specifies the width of the browser









What Is A Span Tag?




  1. Styling the inline element (using a style sheet)
  2. Identify the inline element (using a script)

Syntax


<span></span>



Example






  1. Show the charging percentage
  2. Show the label as red if the battery is not 100% charged and green color if the battery is 100% charged.


Picture showing the output of span tag in html




  1. Update the battery status
  2. Change the color


<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Span Demo</title>
    <style>
        .HundredPercentCharged {
            color: blue;
        }

        .LessThanTenPercentCharged {
            color: red;
        }
    </style>
</head>
<body>
    Your battery is <span class="HundredPercentCharged">100% charged</span> <br />
    Your battery is <span class="LessThanTenPercentCharged">10% charged</span>
</body>
</html>

Try It




Browser Support


Internet ExplorerFirefoxChromeSafariOperaEdge
YesYesYesYesYesYes



Posted By  -  Karan Gupta
 
Posted On  -  Monday, November 21, 2016
 
Updated On  -  Sunday, December 3, 2017

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250