Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best replacement for font tag in html

Tags:

Since the font tag in HTML is being deprecated in HTML5 (and I understand why) is there a clean solution for applying certain attributes and styles to only portions of a paragraph text? I'm using JavaScript to parse an XML file that relies on the fact that the font tag allows portions of wrapping text to be formatted using class-based CSS. I realize the "anchor" (a) tag could also be used for this purpose, but that way seems very backwards and unnatural.

EDIT

When I asked this question (a couple years ago now) I was failing to understand that every DOM element falls into a display category, the two primary categories being:

  • block - insists on taking up its own row
  • inline - falls in line with other inline elements or text

HTML offers two generic container elements, each of which by default adheres to one of these display values; div for block display, and span for inline display.

The span element is the perfect way to designate a certain chunk of text and give it a unique style or ID because you can wrap it around part of a larger paragraph without breaking the selected contents into a new row.

like image 577
Taylor Lopez Avatar asked Oct 09 '13 18:10

Taylor Lopez


People also ask

What can I use instead of font tag?

You can not use the <font> tag in HTML5. Instead, use CSS properties such as font, font-family, font-size and color to format the text in the document.

Why is font tag deprecated?

The W3C wants authors to use CSS, not acute tags and attributes, for explicit control of the font styles, colors, and sizes of the text characters. That's why these extended font tags and related attributes have fallen into disfavor. It's now time for you to eschew the extended font tags, too.

How do you change the font tag in HTML?

To change the text font in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-family, font-size, font-style, etc. HTML5 do not support the <font> tag, so the CSS style is used to change font.

What is the tag for font in HTML?

The <font> tag was used in HTML 4 to specify the font face, font size, and color of text.


2 Answers

The span tag would be the best way.

Although inline CSS is typically not recommended, here is an example:

<p> This is my <span style="font-weight:bold">paragraph</span>. </p> 

span and div are similar, but the div tag is a block element, so it will cause line-breaks. span is an inline tag that can be used inline with your text.

like image 89
Adam Plocher Avatar answered Sep 28 '22 07:09

Adam Plocher


HTML:

<span class="yourstyle"> Text in your style </span> 

CSS:

.yourstyle {             color: red;            } 
like image 22
Igor Avatar answered Sep 28 '22 07:09

Igor