Marginal CSS Attributes - html

How do you guys handle marginal CSS? By marginal, I mean a single word or phrase that needs italics or bolding. It seems silly to declare a 'bold' class with just
Bold { font-weight: bold; }
Or italics, either!
Italic { font-style: italics; }
But I find myself hesitating to put class like that into my css reset.
<p>
<span class="Italic">This</span> man?
<span class="Bold">What</span> are you thinking?
</p>
Obviously if you're going to combine a bunch of properties to make something look different, it makes sense...
.HoverOnMe
{
color: #880;
text-decoration: underline;
font-style: italic;
}
But I'd classify the above css style as 'non-marginal'.
We're taught that elements like <b> and <i> are bad because they mix structure and style, and therefore we shouldn't use them. So what is the right way to handle 'marginal css'?

When you add a class to an element, name that class by what it represents, not what it looks like. class="Italic" is an anti-pattern that completely misses the point of separating content and styling.
<span class="Italic">This</span> man?
<span class="Bold">What</span> are you thinking?
If what you mean to say is that the word “This” is an emphasised word—that is, if you were to read the sentence, you'd change your tone of voice when pronouncing it—then you should say so with a class name like class="emphasised". However you don't need to do that, because there is already an element available in HTML that has exactly that meaning, specifically <em>.
<em>This</em> man?
As luck would have it, browsers will render <em> as italic by default, so you wouldn't need any more CSS.
You shouldn't always use <em> for italics. There are other reasons a word might be italicised. For example it might be a citation (use <cite>), or a phrase in another language (use <span lang="fr">c'est la vie</span>), or it might just be a typographical quirk with no semantic meaning (in which case a plain <span> with styling is fine). Use the element that most closely matches the semantics of what you are trying to say, and adjust the rendering with CSS if the default rendering doesn't match what you wanted it to look like.
There is a second form of emphasis that is rendered as bold by default, <strong>:
<strong>What</strong> are you thinking?
This is usually considered to mean “more emphasised than <em>”. If that is what you were going for, use that tag. But again, don't jump for <strong> just because you want something bold. If it should be bold because it's a heading, use the heading tags. If it should be bold because it's the first line of an article or something, add a class="first-line" (or simply use a CSS :first-line selector, where appropriate).

Instead of <b> and <i> use <strong> and <em>. These have semantic meaning and are often default-styled by browsers to be the same as <b> and <i>, and of course you can control their style like any other element.

I certainly would avoid creating Bold and Italic classes in your CSS stylesheet.
When you say 'Marginal', if you mean that it is like a one-off case and you dont feel you should create a class just for this one case, then what about just using inline CSS?
e.g...
<p>
<span style="font-style:italic">This</span> man?
<span style="font-weight:bold">What</span> are you thinking?
</p>

Why not create a css class that describes the intent rather than the action of emphasizing. You could call it something like "importantWord", and yes, it's fine that it only contains a single rule. The important thing is that if you decide to change the appearance of the style, semantically, it will still make sense.

I think you did it write using . You could use too to render default bold but it would have another meaning since it precise the importance of the text within it.
There's no better way for a one-attribute css rule.

Related

Deprecated code: <b> vs style="font-weight:bold;"

I've always used <b> tag to bold something, because that is the way I was taught to do it a long time ago. But now my IDE always informs me that <b> is deprecated and to use css style. Assuming by that they want me to use <div style="font-weight:bold;">Bold Text</div>. How vital is this message that my IDE is giving me? Should I go back and change all my<b> to style?
Below is an example of both situations. Could someone explain the difference's between both and why <b> is deprecated now?
<b>Bold Text</b>
Vs.
<div style="font-weight:bold;">Bold Text</div>
Would <b> be better because if someone has css turned off on the browser, it would still be show correctly?
The correct question is: "What markup best describes my content?"
Let's start with the <b> tag (which is not deprecated):
The b element represents a span of text to be stylistically offset
from the normal prose without conveying any extra importance, such as
key words in a document abstract, product names in a review, or other
spans of text whose typical typographic presentation is boldened.
...
You should not use b and i tags if there is a more descriptive and
relevant tag available. If you do use them, it is usually better to
add class attributes that describe the intended meaning of the markup,
so that you can distinguish one use from another.
...
It may help to think of b or i elements as essentially a span element
with an automatic fallback styling. Just like a span element, these
elements usually benefit from class names if they are to be useful.
http://www.w3.org/International/questions/qa-b-and-i-tags
By comparison, <strong> has a more specific purpose:
The strong element represents a span of text with strong importance.
http://www.w3.org/TR/html-markup/strong.html
For example:
<p><strong>Warning.</strong> Here be dragons.</p>
Here we emphasize the word "warning" to stress its importance.
But not:
<p><strong>Item 1:</strong> Foo, bar, and baz.</p>
"Item 1" isn't meant to be stressed, so <strong> is the wrong tag. Furthermore, it's possible that the whole structure could be better represented.
If the meaning of the text has strong importance, <strong> is appropriate (just like this line).
Perhaps you just want a thicker font for style purposes and the text has no particular meaning. In that case, neither <strong> nor <b> may be appropriate.
<span class="product-name">Hello World</span>
.product-name { font-weight: bold; }
In all cases:
Use the markup which describes the content.
Do not use inline styles (use an external stylesheet).
Do not name styles based on their visual representation (e.g. naming a style "bold" is a poor choice)
Would <b> be better because if someone has css turned off on the
browser, it would still be show correctly?
No. Use the correct markup for the job. It's fairly unusual for someone using the visual representation of your site to willingly disable the stylesheet, but non-visual consumers care primarily about the structure of your document. A "non-visual consumer" could be a search engine parsing your content or a screen reader application.
Additional Reading:
http://www.w3.org/TR/html51/text-level-semantics.html#the-strong-element
http://www.w3.org/TR/html51/text-level-semantics.html#the-b-element
It's not "vital" if the code still works. Though it would conform to current standards which will give the code a longer future.
The difference is that using CSS separates your styling from your content. <b> is a style, nothing more. And it tightly couples that markup to that style. The separation allows you to emphasize the markup in other ways instead of always using a bold font.
Would be better because if someone has css turned off on the browser, it would still be show correctly?
No, because if the user wants to disable styling then your <b> tag undermines that, because it's mixing styling with content.
You should be using <strong> in place of <b>. You could use styles (text-weight: bold in a separate sheet) if a particular group of text was always going to be bold, and you didn't (or couldn't) want to use <strong> for whatever reason. But I would only go that route if you already were applying other styles to that same element.
If you are talking about SEO
Use <strong> should be SEO friendly too... (focus on the keywords)
and it's important !
I find that using <strong></strong> is the better approach than using <b> or inline styles.

What are some advantages to using <span style="font-weight:bold"> rather than <b>?

I've been learning about semantic HTML, and I keep reading how tags like <i> and <b> should be avoided. But if I don't want to emphasize something, but just bold it visually, why would <b> be any worse than <span class="bold">? What are some advantages to using the more verbose <span class="bold"> syntax?
The issue with b and i elements is that they are not semantic, that is, they are about how things should look, not what they mean.
<span class="bold"> is actually no better, as it is also all about how something should look and is embedded in the page (a class name "bold" is not semantic either). It is better to use meaningful class names.
There are semantic tags, such as strong that are better.
As for class names - using a descriptive name is preferred - so <span class="sub-header"> is better than <span class="bold">, as it has meaning.
It's about the nature of markup. Take away presentation, and what you're left with should still convey your message.
The <b> and <i> tags are deprecated, which is why you shouldn't use them, but if you want to add emphasis to otherwise normal text you should use <strong> and <em> over a CSS solution. Having this in your HTML means that users who are disabled and using alternative browsing technologies like screen readers will still know that you intended emphasis. Adding CSS rules for bold and italic looks pretty but is not accessible.
Also bear in mind that you can then use CSS to apply style to your <strong> and <em> tags.
Why?
From http://www.w3.org/International/questions/qa-b-and-i-tags :
You should always bear in mind that the content of a b element may not
always be bold, and that of an i element may not always be italic. The
actual style is dependent on the CSS style definitions.
<b> means "put some text in bold" -- which is a presentation-related information, and should be in a CSS, instead of the HTML code.
<span class="bold"> just has no meaning at all by itself ; I think this solution should be avoided : with this, your HTML itself doesn't mean anything, and need the CSS so your text is seen as important...
This will work for graphical browsers... but what about other ways of consulting your page ?
Like speach-synthesis or braille-tablets ?
Finally, <strong>, on the other hand, means "this text is important" -- which is probably what you meant in the first place ;-)
span class bold is bad, I've seen too many CSS Rules in the style of
.blue-40 {
// 2011-06-08 Change for Bug 12343
color: #800000;
width: 45%;
}
Semantic HTML is something like
.article-head {
}
.article-body {
}
I personally see no issue with <b> and <i>, although people made arguments to use <strong> and <em> instead because they are more meaningful. At that point, pragmatism kicks in: The only reason I ever would create a class solely for bold text is if I don't control the HTML that gets written to a container that I control.
One argument is always accessibility: If you are reading a document with a screen reader or text-to-speech engine, the concept of bold doesn't exist, but the concept of strong/emphasis does. In practice however, b/string and i/em and synonyms and unlikely to ever change, as much as the purists would like it to.
I personally think the Mozilla Developer Network has a great write up on the <b> tag (as well as the <strong> & <em> tags) and how to use it/them.
The important thing to remember is that the markup up is just as much about styling information as it is language. Keep in mind differences such as styling versus semantic differences (i.e. using bold instead of emphasis [<em>]).

use of native html elements vs css

I am working on some legacy PHP code that holds a ton of in-line styling, one of our objectives is to leverage CSS so the code will be cleaner. One thing that got me thinking is the use of native html elements VS the use of CSS, such as bold and italics.
For example,
<b>this is foo</b>
Or in css
.bold { font-weight: bold;}
<span class="bold">this is foo</span>
While these two do the same thing, which one do you guys prefer and why?
Always use HTML tags when they can add meaning, structure, or semantics to your content. If you want to write the sentence I <strong>love</strong> cheese (where the word "love" should carry particular emphasis), the <strong> tag is the correct choice. CSS is absolutely not an acceptable solution.
Always use CSS when you are changing the visual appearance of your page. The title heading on your page is a <h1>...</h1> (end of story), but you can make it bold or not, big or not, purple or not using CSS.
A good acid test is to imagine how a screen reader will interpret your page. If you view the page without any stylesheets attached, it should ideally show your content in a linear, minimal fashion, that is in fact quite ugly, but that conveys all the content you wanted to include on the page.
I think you're looking at a false dichotomy, <b> or .bold. Given the choice between these two, I'd probably choose stylised spans over use of the <b> tag, but that's purely to divorce presentation from mark-up.
There is, though, the strong tag, which is more semantic than the use of span.bold, and less purely-presentational than b, although it does, obviously, imply a presentational choice. This is my preferred choice over-all.
Instead of using bold (or span class=bold for that matter), you probably should consider the semantics of what you want. Is the text important? Use strong or em (emphasis). This helps on things like search engine visibility as well.
You should choose the tag based on semantics - afterall, CSS can be used to style them to look like anything.
W3C recommends keeping your HTML as semantic as possible. So you should use <strong>, <em> and other HTML tags instead of various <span>s with classes on them.
As a matter of fact you could have all your HTML code with just <div>s, but that doesn't mean you should do it.
As for <b>, <i> and other tags with no meaning, you should discontinue them.
IMHO, CSS is the way to go.
Reasons :
1 - You should not mix your styling code with your content.
2 - Easier to customize/change your final representation in required, or can represent them differently using different css.
3 - Separation of responsibilities in terms of who maintains what
I prefer using the span because it is infinitely stylable. The bold tag is always bold unless you override it, and then it's useless anyway.
Semantically, you should use html to describe the emphasis used here. The <b> is obsoleted and <strong> should be implemented to describe the text. In addition, the css should reflect the styling for the selector:
strong { font-size: whatever; }
<strong>this is foo</strong>
There are stuff like bold letters that I prefer to still leverage to html, SEO mainly. But if you combine more than one stile i.e. Bold and Italic it would be good to have an style called accent maybe. But trying to keep style out of html would make you happy (Less stuff to maintain) and your users happy (less code to transfer, they would access slim pages).

CSS/HTML: What is the correct way to make text italic?

What is the correct way to make text italic? I have seen the following four approaches:
<i>Italic Text</i>
<em>Italic Text</em>
<span class="italic">Italic Text</span>
<span class="footnote">Italic Text</span>
<i>
This is the "old way". <i> has no semantic meaning and only conveys the presentational effect of making the text italic. As far as I can see, this is clearly wrong because this is non-semantic.
<em>
This uses semantic mark up for purely presentational purposes. It just happens that <em> by default renders text in italic and so it is often used by those who are aware that <i> should be avoided but who are unaware of its semantic meaning. Not all italic text is italic because it is emphasised. Sometimes, it can be the exact opposite, like a side note or a whisper.
<span class="italic">
This uses a CSS class to place presentation. This is often touted as the correct way but again, this seems wrong to me. This doesn't appear to convey any more semantic meaning that <i>. But, its proponents cry, it is much easier to change all your italic text later if you, say, wanted it bold. Yet this is not the case because I would then be left with a class called "italic" that rendered text bold. Furthermore, it is not clear why I would ever want to change all italic text on my website or at least we can think of cases in which this would not be desirable or necessary.
<span class="footnote">
This uses a CSS class for semantics. So far this appears to be the best way but it actually has two problems.
Not all text has sufficient meaning to warrant semantic markup. For example, is italicised text at the bottom of the page really a footnote? Or is it an aside? Or something else entirely. Perhaps it has no special meaning and only needs to be rendered in italics to separate it presentationally from the text preceding it.
Semantic meaning can change when it is not present in sufficient strength. Lets say I went along with "footnote" based upon nothing more than the text being at the bottom of the page. What happens when a few months later I want to add more text at the bottom? It is no longer a footnote. How can we choose a semantic class that is less generic than <em> but avoids these problems?
Summary
It appears that the requirement of semantics seems to be overly burdensome in many instances where the desire to make something italic is not meant to carry semantic meaning.
Furthermore, the desire to separate style from structure has led CSS to be touted as a replacement to <i> when there are occasions when this would actually be less useful. So this leaves me back with the humble <i> tag and wondering whether this train of thought is the reason why it is left in the HTML5 spec?
Are there any good blog posts or articles on this subject as well? Perhaps by those involved in the decision to retain/create the <i> tag?
You should use different methods for different use cases:
If you want to emphasise a phrase, use <em>.
The <i> tag has a new meaning in HTML5, representing "a span of text in an alternate voice or mood". So you should use this tag for things like thoughts/asides or idiomatic phrases. The spec also suggests ship names (but no longer suggests book/song/movie names; use <cite> for that instead).
If the italicised text is part of a larger context, say an introductory paragraph, you should attach the CSS style to the larger element, i.e. p.intro { font-style: italic; }
<i> is not wrong because it is non-semantic. It's wrong (usually) because it's presentational. Separation of concern means that presentional information should be conveyed with CSS.
Naming in general can be tricky to get right, and class names are no exception, but nevertheless it's what you have to do. If you're using italics to make a block stand out from the body text, then maybe a class name of "flow-distinctive" would be in order. Think about reuse: class names are for categorization - where else would you want to do the same thing? That should help you identify a suitable name.
<i> is included in HTML5, but it is given specific semantics. If the reason why you are marking something up as italic meets one of the semantics identified in the spec, it would be appropriate to use <i>. Otherwise not.
I'm no expert but I'd say that if you really want to be semantic, you should use vocabularies (RDFa).
This should result in something like that:
<em property="italic" href="http://url/to/a/definition_of_italic"> Your text </em>
em is used for the presentation (humans will see it in italic) and the property and href attributes are linking to a definition of what italic is (for machines).
You should check if there's a vocabulary for that kind of thing, maybe properties already exist.
More info about RDFa here: http://www.alistapart.com/articles/introduction-to-rdfa/
TLDR
The correct way to make text italic is to ignore the problem until you get to the CSS, then style according to presentational semantics. The first two options you provided could be right depending on the circumstances. The last two are wrong.
Longer Explanation
Don't worry about presentation when writing the markup. Don't think in terms of italics. Think in terms of semantics. If it requires stress emphasis, then it's an em. If it's tangential to the main content, then it's an aside. Maybe it'll be bold, maybe it'll be italic, maybe it'll be fluorescent green. It doesn't matter when you're writing markup.
When you do get to the CSS, you might already have a semantic element that makes sense to put italics for all its occurrences in your site. em is a good example. But maybe you want all aside > ul > li on your site in italics. You have to separate thinking about the markup from thinking about the presentation.
As mentioned by DisgruntledGoat, i is semantic in HTML5. The semantics seem kind of narrow to me, though. Use will probably be rare.
The semantics of em have changed in HTML5 to stress emphasis. strong can be used to show importance as well. strong can be italic rather than bold if that's how you want to style it. Don't let the browser's stylesheet limit you. You can even use a reset stylesheet to help you stop thinking within the defaults. (Though there are some caveats.)
class="italic" is bad. Don't use it. It is not semantic and is not flexible at all. Presentation still has semantics, just a different kind from markup.
class="footnote" is emulating markup semantics and is incorrect as well. Your CSS for the footnote should not be completely unique to your footnote. Your site will look too messy if every part is styled differently. You should have some visual patterns scattered through your pages that you can turn into CSS classes. If your style for your footnotes and your blockquotes are very similar, then you should put the similarities into one class rather than repeat yourself over and over again. You might consider adopting the practices of OOCSS (links below).
Separation of concerns and semantics are big in HTML5. People often don't realize that the markup isn't the only place where semantics is important. There is content semantics (HTML), but there is also presentational semantics (CSS) and behavioral semantics (JavaScript) as well. They all have their own separate semantics that are important to pay attention to for maintainability and staying DRY.
OOCSS Resources
Object Oriented CSS
An Introduction To Object Oriented CSS (OOCSS)
How to Write Object Oriented CSS
Getting started with Object-Orientated CSS (OOCSS)
Object-Oriented CSS: What, How, and Why
Diving into Object Oriented CSS
Perhaps it has no special meaning and only needs to be rendered in italics to separate it presentationally from the text preceding it.
If it has no special meaning, why does it need to be separated presentationally from the text preceding it? This run of text looks a bit weird, because I’ve italicised it for no reason.
I do take your point though. It’s not uncommon for designers to produce designs that vary visually, without varying meaningfully. I’ve seen this most often with boxes: designers will give us designs including boxes with various combinations of colours, corners, gradients and drop-shadows, with no relation between the styles, and the meaning of the content.
Because these are reasonably complex styles (with associated Internet Explorer issues) re-used in different places, we create classes like box-1, box-2, so that we can re-use the styles.
The specific example of making some text italic is too trivial to worry about though. Best leave minutiae like that for the Semantic Nutters to argue about.
HTML italic text displays the text in italic format.
<i>HTML italic text example</i>
The emphasis and strong elements can both be used to increase the importance of certain words or sentences.
<p>This is <em>emphasized </em> text format <em>example</em></p>
The emphasis tag should be used when you want to emphasize a point in your text and not necessarily when you want to italicize that text.
See this guide for more: HTML Text Formatting
The i element is non-semantic, so for the screen readers, Googlebot, etc., it should be some kind of transparent (just like span or div elements). But it's not a good choice for the developer, because it joins the presentation layer with the structure layer - and that's a bad practice.
em element (strong as well) should be always used in a semantic context, not a presentation one. It has to be used whenever some word or sentence is important. Just for an example in the previous sentence, I should use em to put more emphasis on the 'should be always used' part. Browsers provides some default CSS properties for these elements, but you can and you're supposed to override the default values if your design requires this to keep the correct semantic meaning of these elements.
<span class="italic">Italic Text</span> is the most wrong way. First of all, it's inconvenient in use. Secondly, it suggest that the text should be italic. And the structure layer (HTML, XML, etc.) shouldn't ever do it. Presentation should be always kept separated from the structure.
<span class="footnote">Italic Text</span> seems to be the best way for a footnote. It doesn't suggest any presentation and just describes the markup. You can't predict what will happen in the feature. If a footnote will grow up in the feature, you might be forced to change its class name (to keep some logic in your code).
So whenever you've some important text, use em or strong to emphasis it. But remember that these elements are inline elements and shouldn't be used to emphasis large blocks of text.
Use CSS if you care only about how something looks like and always try to avoid any extra markup.
I think the answer is to use <em> when you intend emphasis.
If when reading the text to yourself, you find that you use a slightly different voice to emphasise a point, then it should use <em> because you would want a screen reader to do the same thing.
If it is purely a style thing, such as your designer has decided that all your <h2> headings would look better in italic Garamond, then there is no semantic reason to include it in the HTML and you should just alter the CSS for the appropriate elements.
I can't see any reason to use <i>, unless you specifically need to support some legacy browser with no CSS.
I'd say use <em> to emphasize inline elements. Use a class for block elements like blocks of text. CSS or not, the text still has to be tagged. Whether its for semantics or for visual aid, I'm assuming you'd be using it for something meaningful...
If you're emphasizing text for ANY reason, you could use <em>, or a class that italicizes your text.
It's OK to break the rules sometimes!
OK, the first thing to note is that <i> has been deprecated, and shouldn't be used <i> has not been deprecated, but I still do not recommend using it—see the comments for details. This is because it goes entirely against keeping presentation in the presentation layer, which you've pointed out. Similarly, <span class="italic"> seems to break the mold too.
So now we have two real ways of doing things: <em> and <span class="footnote">. Remember that em stands for emphasis. When you wish to apply emphasis to a word, phrase or sentence, stick it in <em> tags regardless of whether you want italics or not. If you want to change the styling in some other way, use CSS: em { font-weight: bold; font-style: normal; }. Of course, you can also apply a class to the <em> tag: if you decide you want certain emphasised phrases to show up in red, give them a class and add it to the CSS:
Fancy some <em class="special">shiny</em> text?
em { font-weight: bold; font-style: normal; }
em.special { color: red; }
If you're applying italics for some other reason, go with the other method and give the section a class. That way, you can change its styling whenever you want without adjusting the HTML. In your example, footnotes should not be emphasised—in fact, they should be de-emphasised, as the point of a footnote is to show unimportant but interesting or useful information. In this case, you're much better off applying a class to the footnote and making it look like one in the presentation layer—the CSS.
Use <em> if you need some words/characters in italic in content without other styles. It also helps make content semantic.
text-style is better suited for multiple styles and no semantic need.
DO
Give the class attribute a value indicating the nature of the data (i.e. class="footnote" is good)
Create a CSS style sheet for the page
Define a CSS style that is attached to the class that you assign to the element
.footnote {
font-style:italic;
}
DO NOT
Don't use <i> or <em> elements - they're unsupported and ties the data and presentation too close.
Don't give the class a value that indicates the presentation rules (i.e. don't use class="italic").

Alternative to the HTML Bold tag

Okay, so I know that in HTML you can use the <b> tag, but isn't there a "weight=bold" attribute that I can use in the <p> tag?
Or is that in CSS, or Javascript?
Also consider the <strong> tag. It's much better for screen readers and therefore better for accessibility. Search engines also use <strong> tags to determine important content similar to how they use header tags <h1>, <h2>, etc (although <b> will also have similar meaning to search engines). If you want to stress importance of text, use <strong>. If you don't want to stress importance, use the <b> tag or use the font-weight:bold; style on the element or in the CSS.
Although, if you are bolding the entire paragraph, it's probably better to use the CSS option. This will reduce the affect on screen readers and it probably doesn't make sense to have an entire paragraph emphasized. But on the other hand, I've seen bold used to emphasize an entire paragraph before for good reason. In which case, font-weight:bold; is what you want to use, likely in a class/style.
In the end, <strong>, <b> or font-weight:bold; will all work and accomplish something similar visually (probably exactly the same), but they have slightly different meanings. Also, make sure that if what you're bolding is a header, use the header tags: <h1>, <h2>, etc.
You're thinking of the CSS property font-weight:
p { font-weight: bold; }
If the text's meaning is semantically strong, use the strong element. If not, use a semantic named class (one that clearly shows the meaning of the element, don't mix presentation and data by calling it bold etc) and reference it in your CSS.
HTML
<span class="important-message">I'm important!</span>
CSS
.important-message {
font-weight: bold;
}
Some people still use the b element as a presentational hook, but it hasn't been deprecated, though most people favour the strong element nowadays. Just make sure they are used correctly.
The <b> tag is alive and well. <b> is not deprecated, but its use has been clarified and limited. <b> has no semantic meaning, nor does it convey vocal emphasis such as might be spoken by a screen reader. <b> does, however, convey printed empasis, as does the <i> tag. Both have a specific place in typograpghy, but not in spoken communication, mes frères.
To quote from http://www.whatwg.org/
The b element represents a span of text to be stylistically offset from the normal prose without conveying any extra importance, such as key words in a document abstract, product names in a review, or other spans of text whose typical typographic presentation is boldened.
You can make text or words Bold with using <b>Text</b> tag.
You can also use <strong>Text</strong> tag
Head tags <h1>, <h2>, <h3>, ... are default bolded tags and make your text Bold by default unless you change their style with CSS
Above tags was available in HTML but if you like to change the style with CSS you can use
font-weight:bold
Its in CSS you have to set font-weight: bold; as style
You can code like below..
<html>
<head>
<style>
p.boldstats{
font-weight: bold
}
</style>
</head>
<body>
<p class="boldstats"> The bold finder </p>
</body>
</html>
You can use the font-weight attribute on your
For example:
<p>This is my paragraph</p>
You can either have your CSS inline as below:
<p style="font-weight:bold;">This is my paragraph</p>
Or have it in your external CSS stylesheet as below:
p{
font-weight:bold;
}
It's all historical and dates from a time where dinosaurs walked the earth and CSS didn't exist.
More seriously, forget about the <b/> tag and use font-weight:bold in a CSS rule :)
<b> is a last resort
You can use <b>, but only as a last resort. There are a variety of elements that work as good alternatives to <b>, here they are in order of most usefulness:
More useful alternatives
For important text: <strong>
For stress emphasized text: <em>
For headings, not just page headings but paragraph headings and others of all kinds: <h1> through <h6>
The practical edge case for use of <b>
The only case where I would advocate using <b> is if
you have styled <strong> in a different way that you don't want displaying for the text that you have in mind,
you don't want italic emphasis or a heading, and
you are about to use an inline span or a span with a class just for bolding text. (For example: <span class='bold'>)
Then it's reasonable to use <b> instead, because in that case it'll probably be cleaner/shorter and more semantic than an unsemantic span, and terceness/readability is a good reason for making that choice, since b has been redefined for use as an element denoting printed emphasis.
you could also do <p style="font-weight:bold;"> bold text here </p>
#bold{
font-weight: bold;
}
#custom{
font-weight: 200;
}
<body>
<p id="bold"> here is a bold text using css </p>
<p id="custom"> here is a custom bold text using css </p>
</body>
I hope it's worked
Maybe you want to use CSS classes?
p.bold { font-weight:bold; }
That way you can still use <p> as normal.
<p>This is normal text</p>
<p class="bold">This is bold text</p>
Gives you:
This is normal text.
This is Bold Text.
A very old thread, I know. - but for completeness:
I use <span class="bold">my text</span>
as I upload the four font styles: normal; bold; italic and bold italic into my web-site via css.
I feel the resulting output is better than simply modifying a font and is closer to the designers intention of how the boldened font should look.
The same applies for italic and bolditalic of course, which gives me additional flexibility.
What you use instead of the b element depends on the semantics of that element's content.
The elements b and strong have co-existed for a long time by now. In HTML 4.01, which has been superseded by HTML5, strong was meant to be used for "strong emphasis", i.e. stronger emphasis than the em element (which just indicated emphasis). In HTML 5.2, strong "represents strong importance, seriousness, or urgency for its contents"; the aspects of "seriousness" and "urgency" are new in the specification compared to HTML 4.01. So if you used b to represent content that was important, serious or urgent, it is recommended that you use strong instead. If you want, you can differentiate between these different semantics by adding meaningful class attributes, e.g. <strong class="urgent">...</strong> and <strong class="warning">...</strong> and use appropriate CSS selectors to style these types of "emphasis" different, e.g. using different colours and font sizes (e.g. in your CSS file: strong.warning { color: red; background-color: transparent; border: 2px solid red; }.).
Another alternative to b is the em element, which in HTML 5.2 "represents stress emphasis of its contents". Note that this element is usually rendered in italics (and has therefore often been recommended as a replacement for the i element).
I would resist the temptation to follow the advice from some of the other answers to write something like <strong class="bold">...</strong>. Firstly, the class attribute doesn't mean anything in non-visual contexts (listening to an ePub book, text to speech generally, screen readers, Braille); secondly, people maintaining the code will need to read the actual content to figure out why something was bolded.
If you used b for entire paragraphs or headings (as opposed to shorter spans of texts, which is the use case in the previous bullet point), I would replace it with appropriate class attributes or, if applicable, WAI-ARIA roles such as alert for a live region "with important, and usually time-sensitive, information". As mentioned above, you should use "semantic" class attribute values, so that people maintaining the code (including your future self) can figure out why something was bolded.
Not all uses of the b may represent something semantic. For example, when you are converting printed documents into HTML, text may be bolded for reasons that have nothing to do with emphasis or importance but as a visual guide. For example, the headwords in dictionaries aren't any more "serious", "urgent" than the other content, so you may keep the b element and optionallly add a meaningful class attribute, e.g. <b class="headword"> or replace the tag with <span class="headword"> based on the argument that b has no meaning in non-visual contexts.
In your CSS file (instead of using style attributes, as some of the other answers have recommended), you have several options for styling the "bold" or important text:
specifying different colours (foreground and/or background);
specifying different font faces;
specifying borders (see example above);
using different font weights using the font-weight property, which allows more values than just normal and bold, namely normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900,
etc.
Note that support for numeric font-weight values has not always been great.
On a sidenote the below code will also make it bold.
<strong> text here </strong>
<p style="font-weight:bold;"></p>
Nowadays people tend to use website builders (CMS like Wordpress) instead of coding their own blog from scratch. Even professional web developers do it because it's faster.
It would be nice if you could mention the advantages and things to keep in mind when coding your own blog in real life, for example:
More flexibility (customization)
Pay a domain name
Pay and choose a web hosting
Security and maintenance
Copyright and license of some website builders' templates and graphics. Your website could be locked to a particular web host if you used your host's website builder. So you cannot move to another web host, because if you do you could no longer use that template.
Experience trouble when asking for website builder's tech support when the website goes down.
Some templates are not search engine friendly and this affects your website ranking (SEO)
Anyways, you can use css/css3 or JavaScript for making interactive webpage. Even you can upload your all sort of code into a server formatting the default blog theme.
You can use following :
<p id="p1">Some Text here </p>
#p1{
font-weight: bold;
}
OR
<Strong><p>Some text here </p></strong>
OR
You can use <h1> tag which is somewhat similar to bold
The answer by #Darryl Hein is correct despite one point - <b> is not recommended at all since XHTML, because it's not semantic.
<strong> means semantically highlighted text
font-weight: bold means visually highlighted text
<strong> can be css-tuned to not be bold, though it's a conventional default. It can be made red, or italic, or underlined (though all these possibilities are not really user-friendly). Use it for phrases / words in text, not because of visual design, but related to their meaning
font-weight: bold should be used for design-related bold parts, like headers, sub-headers, table header cells etc.
Use the <strong> tag because it's more semantic. <b> has been depreciated so it's best not to use it. Also bold text is given more Search Engine Optimisation (SEO) weight so it's always best to use a real <strong> rather than making a <p> or <span> bold using CSS.