Jump to content


Photo

What Is Correct Tag To Use To Change Fonts?


  • This topic is locked This topic is locked
5 replies to this topic

#1 limitphp

limitphp

    Advanced Member

  • Members
  • PipPipPip
  • 706 posts

Posted 07 December 2012 - 01:43 PM

If I have a section of text in a table or div, or something else, and I just want to change the font color of one word in the text, what is the correct tag to use to change the font color? I understand I should use the style='color:', but what tag is the most appropriate for this?

#2 SocialCloud

SocialCloud

    Advanced Member

  • Members
  • PipPipPip
  • 613 posts

Posted 07 December 2012 - 02:39 PM

<font color="blah">word</font>


#3 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,707 posts
  • LocationBonita, FL

Posted 07 December 2012 - 03:20 PM

<font color="blah">word</font>


No, <font> has been deprecated for a while, and is no longer valid in html5.

@limitphp You should use CSS to apply the font you need to the element containing your text.  The element you use should be sematic for whatever the text represents/means on the page.  If you need a generic element to wrap a small bit of text, use <span> or <div> depending on if you need inline or block level elements.

Edited by kicken, 07 December 2012 - 03:23 PM.

Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#4 limitphp

limitphp

    Advanced Member

  • Members
  • PipPipPip
  • 706 posts

Posted 07 December 2012 - 03:20 PM

<font color="blah">word</font>


I thought html 5 has gotten rid of the font tag. I understand it still works in browsers, but is that really the appropriate tag to use? Is there a tag that would be more in line with the new standards?

#5 limitphp

limitphp

    Advanced Member

  • Members
  • PipPipPip
  • 706 posts

Posted 07 December 2012 - 03:21 PM

No, <font> has been deprecated for a while, and is no longer valid in html5.

@limitphp You should use CSS to apply the font you need to the element containing your text. The element you use should be sematic for whatever the text represents/means on the page. If you need a generic element to wrap a small bit of text, use <span> or <div> depending on if you need inline or block level elements.


Div would knock the text after it down on the next line, unless I added some style properties to the div. So, perhaps span is the best tag to use to change the font of one word in a section of text?

#6 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 07 December 2012 - 06:18 PM

Span is probably best, but you can always use display: inline; to make a block element (div, p) look like a span does.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com