Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are alternatives to the span-element? [duplicate]

Tags:

html

css

say you are working without the <p> element in HTML. How would you stylize a simple text with css? What HTML-Tag would you take? I always used <span>, but now I saw that span should always be used to group inline-elements (for example <p>). And thats not the case in my example.

Thanks, phpheini

like image 272
phpheini Avatar asked Feb 28 '11 01:02

phpheini


People also ask

What can you replace span with?

Div tags are basically <span> tags for block elements instead of inline elements. So if I want for example a text to have a specific size I should use a div where my text is inside? Is this really a good way? Yep.

Can I use div instead of span?

Span and div are both generic HTML elements that group together related parts of a web page. However, they serve different functions. A div element is used for block-level organization and styling of page elements, whereas a span element is used for inline organization and styling.

Can I use SPAN instead of P?

Well answer to your question is yes and no,What I mean by that is "p" is a block level tag for paragraphs. "span" is a line level tag that in and of itself doesn't do anything, but is useful for defining a specific style to a string. "span" can be used within "p", but "p" cannot be used within "span".

Can I use value attribute for span?

The val() method looks for for the an attribute named 'value' on the selector. eg. In a span element, you would typically not use value, but have text inside the element.


2 Answers

First you should look whether some tag matches semantically. For instance, you might have a text which requires emphasis, in which case em is the best choice. Another case is if you have a heading, which you could style with h1, ..., h6. Always first consider this option!

If there really is no meaning to the text you want to style, or at least, not a meaning supported by css, you can use either span (for inline text) or div (for block elements).

like image 192
markijbema Avatar answered Oct 05 '22 07:10

markijbema


You're free to use any tag you wish... (Within reason); Just make sure it's semantic.

Just a few you could use: <div> <em> <strong> <small> <pre>

like image 26
Paul Millar Avatar answered Oct 05 '22 08:10

Paul Millar