span-html

Span Html

The HTML range component is a nonexclusive inline compartment for inline components and substance. It used to gather components for styling purposes (by utilizing the class or id credits), A superior method to utilize it when no other some other semantic component is accessible. length is fundamentally the same as the div tag, yet div is a block-level tag and range is an inline tag. Length tag is a matched label implies it has both open(<) and shutting (>) tag and it is obligatory to close the tag.

  • The range tag is accustomed to gathering of inline-components.
  • The range tag doesn’t roll out any visual improvement without help from anyone else.
  • range is fundamentally the same as the div tag, however div is a block-level tag and length is an inline tag.

Tag is composed like:

Grammar:

<span class=””>Some Text………….</span>

In underneath model guess we need to compose multiple times GeeksforGeeks in three lines with intense, italic, underline, in green tone with textual style family = dispatch new so we need to utilize numerous HTML labels, for example, <b>, <i>, <u>, <font> for each time in each line and we need to make changes need to adjust each tag.

Example:

<!DOCTYPE html>
<html>
<head>
    <title>GeeksforGeeks span tag</title>
</head>
<body>
    <h2>Welcome To GFG</h2>
 
<!-- First Line  -->
<font color="009900" size="6">
    <b>
       <u>
           <i>GeeksforGeeks</i>
       </u>
    </b>
</font>
 
    </br>
 
<!-- Second Line  -->
<font color="009900" size="6">
    <b>
       <u>
           <i>GeeksforGeeks</i>
       </u>
    </b>
</font>
 
    </br>
 
<!-- Third Line  -->
<font color="009900" size="6">
    <b>
       <u>
           <i>GeeksforGeeks</i>
       </u>
    </b>
</font>
     
 
</body>
</html>                    

Output:

Be that as it may, by utilizing <span> label we can lessen code and HTML Attributes see underneath model will show a similar yield as above model with utilizing <span> tag by applying CSS in a range tag.
Example:

<!DOCTYPE html>
<html>
   <head>
      <title>GeeksforGeeks span tag</title>
      
     <!-- style for span tag  -->
     <style type=text/css>
         span{
         color: green;
         text-decoration: underline;
         font-style: italic;
         font-weight: bold;
         font-size: 26px;
         
      </style>
   </head>
   <body>
      <h2>Welcome To GFG</h2>
      <span>GeeksforGeeks</span></br>
      <span>GeeksforGeeks</span></br>
      <span>GeeksforGeeks</span></br>
   </body>
</html>

Output:

As we probably am aware range is an inline label it accepts space as much as required and leaves space for other component let see it in underneath model every one of the four-length component will show in a similar line on the grounds that each label takes just important space and rest of room free for different components.
Example:

<!DOCTYPE html>
<html>
   <head>
      <title>GeeksforGeeks span tag</title>
   </head>
   <body>
      <h2>Welcome To GFG</h2>
       <!-- span tags with inline style/css  -->
      <span style="background-color:powderblue;">
       GFG</span>
      <span style="background-color: lightgray;">
      -Contribute-</span>
      <span style="background-color: yellow;">
      Article</span>
      <span style="background-color: lightgreen;">
      GCET</span>
   </body>
</html>

Output:

A span tag can be used to set color/background color a part of a text: In below example inside paragraph applying three times span tag with different style.
Example:

<!DOCTYPE html>
<html>
   <head>
      <title>GeeksforGeeks span tag</title>
   </head>
   <body>
      <h2>Welcome To GFG</h2>
 
      <!-- Inside paragraph applying span tag with different 
      style -->
      <p><span style="background-color:lightgreen">
         GeeksforGeeks</span> is A Computer Science
         Portal where you can<span style="color:blue;">
         Publish</span> your own <span style=
         "background-color:lightblue;">articles</span>
         and share your knowledge with the world!!
      </p>
   </body>

Output:
Control javascript with length tag: In underneath model we add a range tag inside section with id=”demo” we can changes its content by applying javascript in this model GFG will be changed “GeeksforGeeks” subsequent to tapping on Button.

Example:

<!DOCTYPE html>
<html>
   <body>
      <h2>Welcome to GFG</h2>
      <p> <span id="demo"
         style="background-color:lightgreen;">GFG</span>
      A computer Science portal for Geeks</p>
 
    <!-- creating button in java script  -->
    <button  type="button" onclick=
         "document.getElementById('demo').innerHTML =
                'GeeksforGeeks!!!'">Change Text!</button>
   </body>
</html>

Output:

Difference Between Div tag and span tag

The div and range tag are two regular labels when making pages utilizing HTML and perform distinctive usefulness on them while div tag is a square level component and length is inline component The div tag makes a line break and of course makes a division between the content that comes after the tag as started and until the label closes with </div>. div tag makes separate boxes or compartments for all components inside this label like content, pictures, sections.

PropertiesDiv TagSpan Tag
Elements TypesBlock-LevelInline
Space/WidthContain Whole Width AvailableTakes only required Width
ExamplesHeadings, Paragraph, formAttribute, image
UsesWeb-layoutcontainer for some text
AttributesNot required, with common css, classNot required, with common css, class

The range tag doesn’t make a line break similar to a div tag, yet rather permits the client to isolate things from different components around them on a page inside a similar line. dodging of the line break, results just that chose text to change, keeping the wide range of various components around them same.

Beneath model will show the contrast among range and div tag while div tag contains entire width and length tag contain just required width and rest parts are free for another component.

<strong>Example:</strong>
<html>
   <head>
      <title>gfg</title>
      <style type=text/css>
         p{
         background-color:gray;
         margin: 10px;
         }
          
          
         div
         {
         color: white;
         background-color: 009900;
         margin: 2px;
         font-size: 25px;
         }
         span
         {
         color: black;
         background-color: gray;
         margin: 5px;
         font-size: 25px;
         }
      </style>
   </head>
   <body>
<!-- below some div tags -->
 
      <div > div tag   </div>
      <div > div tag   </div>
      <div > div tag   </div>
      <div > div tag   </div>
       
<!-- below some span tags -->
      <span>span-tag</span>
      <span>span-tag</span>
      <span>span-tag</span>
      <span>span-tag</span>
   </body>
</html>

Output:

Supported Browser: Supported browsers are listed below

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari