Showing posts with label CSS3. Show all posts
Showing posts with label CSS3. Show all posts

Monday, 27 August 2012

Using CSS3 Fonts

CSS3 offers a variety of enhanced features designers and developers can use to create more engaging sites than ever before. CSS3 fonts are among the most significant developments for designers. Essentially, CSS3 allows you to use any font you want within your sites, regardless of whether the user has it installed or not. This is pretty exciting for designers, as user font restrictions have long been a major hassle when implementing designs.

In the past, your Web pages could only display fonts the user had installed on their computer. This meant that whatever font you specified in your CSS code, your site may still not have appeared the way you wanted it to because you had no way of knowing in advance whether any particular user would have that font.You could of course specify fonts to use if your chosen font was not installed, and could use generic descriptions of fonts so that the browser could use whatever font of that type the user did have, for example sans serif. However, even the best case scenario meant an unpredictable user experience.

The font you use in a Web page can have a massive impact on the visual style and usability of the site as a whole, so being able to choose fonts freely is a huge step forward for Web design.

Providing Fonts

CSS3 allows you to use any font because you essentially provide that font as one of your website resources, deploying it from the Web server in the same way you would other style elements such as images.

To include the fonts you want, upload them to your server along with your other resources, taking a note of the location you have them stored at, relative to your site. You can use True Type Fonts, which are saved with ".ttf" extension, OpenType Fonts, which are saved with ".otf" extension and Embedded OpenType Fonts, which are saved with ".eot" as the extension. However, Internet Explorer only supports EOT, while Firefox, Opera, Safari and Chrome support OTF and TTF.

As with most CSS3 properties, older browsers do not support the use of CSS3 fonts in this way at all.

The Font Face Rule

CSS3 uses the font-face declaration to support fonts stored on the server within your Web page designs. The first step in using this technique is defining a font face within the CSS code for your page. You can use the following outline to define a font:

@font-face {
/*give the font a name*/
font-family: productDescriptionFont;
/*tell the browser where to find it*/
src: url('fonts/Really_Cool.ttf'), url('fonts/Really_Cool.eot');
}

Notice that the source URL is provided twice, once for Internet Explorer (with ".eot") and once for the other supporting browsers. In this case the fonts are stored in a directory named "fonts" that is itself in the same directory as the Web page/ CSS file - wherever this code is stored. The font is named "Really_Cool" just as an example. You should of course alter your code to suit the name and location of your own fonts.

So far we have defined a font, but have not applied it to any Web page elements yet.

Applying the Font


You can apply the font you defined to Web page elements using the usual CSS identifiers. To apply it to all div elements with "description" as the class name, for example in a retail website, use the following code:

div.description {
/*use the font name defined earlier*/
font-family:productDescriptionFont;
}

Additional Options

You can use additional options within your font-face definition section. For example, if you use a bold font within your site, you need to include a bold specifier for font-weight within your font-face declaration, if you want italics, you can include it within a font-style declaration and so on. These are optional - the only required ingredients in a font-face section of CSS3 code are the name you want to use to refer to your font and the URL indicating its location on your server.

Whatever rules you apply to your font within the font-face section will be displayed within any Web page elements you apply the font to using its name. This can help to keep your CSS3 code tidy, as you only need one line to apply the font and can apply it within as many CSS declarations as you like. If you decide you want to make a change to the font, you only have to do it within the font-face declaration and it will be reflected throughout your site.

Conclusion

It might seem a bit soon to get excited about emerging technologies and standards such as HTML5 and CSS3, but many of your website users will already have supporting browsers. While it's vital to make sure you accommodate those users without the most recent browser programs, there's absolutely no reason you can't start providing the improved visual effects such as CSS3 fonts to everyone else.

Useful Links

Monday, 23 July 2012

Why Web Developers are Excited About HTML5 and CSS3

If you are involved in Web design, development or just the Web itself in any way, you will almost certainly have become aware of the excitement about the emerging developments in HTML5 and CSS3. This article will attempt to explain some of the reasons for this excitement. HTML5 and CSS3 represent more than a normal update of the languages in question, as they include a number of substantial changes that promise to fundamentally alter the way developers create pages and sites.

OK, so what are HTML5 and CSS3 anyway?

HTML is the main markup language (Hypertext Markup Language) used in Web pages. When you visit a website, the content items you see (text, images, media etc) are included in HTML markup code. HTML uses tagged code to define the overall structure of a page, with elements enclosing the content items. When your browser receives the HTML markup code for a page, it interprets it and presents it to you accordingly.

While HTML defines page structure, CSS (Cascading Style Sheet) code determines the styling of a page, including layout and various other visual aspects of what you see. The way the content of a page is displayed is therefore determined by both HTML and CSS code. HTML5 and CSS3 are the most recent versions of these two specifications. Essentially, with HTML5 and CSS3, developers have new techniques to choose from when building pages.

Most websites use client side scripting in JavaScript in conjunction with HTML and CSS. This allows developers to deliver interactive components. HTML5 and CSS3 include new options for such interactive sites, including the ability to build advanced media items such as animation and drawing functions.

Fine, what does HTML5 offer over previous versions then?

HTML5 introduces a range of new elements that developers can utilise. The most notable new elements are the structural elements, media elements including canvas, and new input elements for capturing user information through website forms. The structural tags include "header", "footer", "article", "section", "nav" and "aside". These allow developers to define sections of a page in a more logical, meaningful way than before. HTML5 also includes new tags for embedding media items such as audio and video in a much more straightforward way. The canvas element is one of the most interesting additions, as Web pages can create graphics using JavaScript drawing functions, building these graphic items while the user is viewing the page.

And CSS3, what does it bring to the table?

CSS3 includes a variety of new properties and functions, allowing developers to create a greater level of interaction than before. The transform and transition functions create interactive animations in both 2D and 3D, while the "keyframes" rule defines animated sequences that elapse over time. CSS3 also introduces advanced user interface styling and the ability to use fonts without the user having them installed on their own computer.

What does semantics have to do with this?

You will see people referring to emerging techniques in Web design as being semantic. This basically means that the actual markup for a page will include an indication of semantics, or meaning, by letting the browser know something about the content of an element. For example, in the past many HTML elements simply grouped a chunk of Web page content in a meaningless way. The HTML defined the content and the CSS styled it, with only the developer and user interpreting the meaning of the content in any way. With the new structural elements in particular, HTML5 markup indicates a level of meaning that the browser can interpret and use to make the page more accessible to the user, whatever their environment happens to be.

How do HTML5 and CSS3 relate to Flash?

Many people are also making claims about the impact that HTML5 and CSS3 will have on other technologies such as Flash. It's certainly still a bit early to make huge claims about how much longer Flash will last. However, with HTML5 and CSS3, developers can achieve the kinds of interactive multimedia component that was previously mainly done in Flash. By using these new specifications instead, developers can create the same results in a way that is more accessible to different users.

Sounds good, why isn't this stuff all over the Web already?


The main factor delaying the adoption of HTML5 and CSS3 is browser support. The main browsers are all working on increasing support of these new standards, some faster than others, but full support is still a long way off. For this reason developers cannot assume that users will be able to engage with new effects created using the most recent specifications, and must provide alternatives for users with older browsers.

See also:
An Introduction to HTML5 Features
How To: HTML5 Local Storage
Using CSS3 Fonts
How to Get Started with Web Development