0

Can we assign width and height to a <span> element? If not, how can we make it accept these properties?

author
pranav m
easy
0
17

Answer

By default, <span> is an inline element, and inline elements don’t respect width and height — they only expand as much as their content requires.

To make a <span> accept width and height, you need to change its display type:

Convert to block or inline-block:

span {
display: inline-block; /* or block */
width: 100px;
height: 50px;
background: lightblue;
}

Click to Reveal Answer

Tap anywhere to see the solution

Revealed

Comments0
    Can we assign width and height to a <span> element? If not, how can we make it accept these properties? - span | EBAT