Wood textures with Photoshop

Photoshop wood effects: pine, cherry and mahogany

I needed to try out some wood textures for a possible up and coming project, so I set myself to work finding tutorials which would assist me in doing so. I found two good ones: My Ink Blog – Realistic wood tutorial and PSD Tuts – Create a wood panel texture in Photoshop. So, I had a play around, and created a hybrid version using the two tutorials as guides.

Here is my method (of course, huge credit goes to the two tutorials mentioned above!):

  1. Open up a nice big new canvas in Photoshop; it depends on how big you want the texture, but mine was 1000 x 1000px so I had a lot of space to play with
  2. Set foreground colour to white and background colour to black
  3. Go to Filter > Render > Clouds and you should see some rough cloud shapes, similar to below: Photoshop Clouds filter
  4. Go to Filter > Blur > Motion Blur and set the angle to vertical or horizontal, depending on which direction you’d like the wood grain to run (or even diagonal if you’d prefer), and the distance to 999px Photoshop Motion Blur filter
  5. Go to Filter > Brush Strokes > Accented Edges and set edge with to 2, edge brightness to 42 and smoothness to 4 Photoshop Accented Edges filter
  6. Go to Filter > Artistic Filters > Dry Brush and set brush size to 2, brush detail to 9 and texture to 2 Photoshop Dry Brush filter
  7. Go to Filter > Artistic Filters > Film Grain and set grain to 1, highlight area to 0 and intensity to 0 Photoshop Film Grain filter
  8. Choose the colour of your wood by going to Image > Adjustments > Hue/Saturation, set it to colorize and drag the sliders around to get the colour you require, then to improve the contrast, go to Image > Adjustments > Levels and adjust the sliders to your heart’s content. It’s probably a good idea to get a reference image for the wood type you are going for to get an accurate hue Colouring the wood texture with Hue/Saturation in Photoshop Adjusting the levels of the wood texture in Photoshop
  9. Go to Filter > Liquify and use the turbulence tool to curve some of the lines Turbulence tool within the Liquify filter in Photoshop to create curved lines
  10. Still in liquify mode, use the bloat tool to expand any possible knot locations, then use the Twirl tool on that same area to create a swirled area for the knot. Again, for this step it is a good idea to get an image of the wood type you are aiming for to get the correct number and size of possible knots for a more realistic feel Bloat tool within the Liquify filter in Photoshop to create spots for knots in the wood Twirl tool within the Liquify filter in Photoshop to create the appearance of knots in the wood texture
  11. Add a new layer and fill it with a darker colour from your range
  12. Go to Filter > Render > Fibers with a variance of 28 and a strength of 50 Photoshop Fibers filter applied to a new layer
  13. Set the layer style to screen and reduce the opacity to about 10-15% so the fibre pattern adds extra texture to the wood Reduced opacity of the Fibers layer
  14. Erase parts of the fibre layer where the knots are Finished wood grain texture
Posted in Photoshop | Tagged | Leave a comment

Styled forms using HTML5, CSS3 and jQuery

For a long time, I have wanted to create a generic form with HTML5 and CSS3 which looks good and has some nice subtle effects, which I can copy and apply to any projects I am working on. This post will only cover the aesthetics, so it’ll have to be configured to actually work! I used this tutorial as a guide to building my HTML5 form, so some credit definitely goes to them.

Styled form using HTML5, CSS3 and jQuery

View demo

The demos I have created are light and dark versions of a sample contact form, containing (hopefully) any element that would be required of a contact form and styled up with CSS. My demo contact form has the following:

  • Fields have rounded corners, inside shadow and outside shadows to create the inset effect
  • Fields have animated focus, and the first field is highlighted automatically on page load
  • Fields are specialised for email address, website address and telephone number
  • The name, email address and message fields are required for the form to be submitted
  • Checkboxes, radio buttons and select elements have been styled using a jQuery plugin
  • Error and success styles have been provided at the top of the form, for when the form is fully operational
  • Submit button has a subtle animated colour change on hover

Markup

HTML

<form method="post" action="process.php">
    <ul class="errors">  
        <li id="info">There were some problems with your form submission:</li>  
    </ul>  
    	
    <p class="success">Thanks for your message! We will get back to you ASAP!</p> 
            
    <label for="name">Name <span class="required">*</span></label>
    <input type="text" id="name" name="name" value="" autofocus="autofocus" placeholder="Joe Bloggs" required="required" />
            
    <label for="email">Email <span class="required">*</span></label>
    <input type="email" id="email" name="email" value="" placeholder="yourname@email.com" required="required" />
            
    <label for="phone">Phone</label>
    <input type="tel" id="phone" name="phone" value="" />
            
    <label for="website">Website</label>
    <input type="text" id="website" name="website" value="http://" />
            
    <div class="inputContainer">
        <label for="subject">Subject</label>
        
        <div class="selectContainer">
            <select id="subject" name="subject" class="styled">  
                <option value="subject1">Subject 1</option>  
                <option value="subject2">Subject 2</option>  
                <option value="subject3">Subject 3</option>  
            </select> 
        </div>
    </div>
            
    <div class="inputContainer">
        <p>Which radio button would you like to select?</p>
        
        <input type="radio" id="radio1" name="radio" value="radio1" class="styled" checked />
        <label for="radio1" class="radioButton">Radio button 1</label>
        <input type="radio" id="radio2" name="radio" value="radio2" class="styled" />
        <label for="radio2" class="radioButton">Radio button 2</label>
    </div>
            
    <label for="message">Message <span class="required">*</span></label>
    <textarea id="message" name="website" placeholder="Write your message here..."></textarea>
            
    <div class="inputContainer">
        <input type="checkbox" id="check1" name="check1" value="check1" class="styled" />
        <label for="check1" class="checkBox">Sign up to newsletter</label>
    </div>
            
    <input type="submit" id="submit" class="submit" value="Submit" />  
</form>

CSS (Light coloured version – view the demo for the CSS for the dark version)

form {
    background: #f3f3f3;
    padding: 20px;
    border-radius: 10px;
    display: inline-block;
}

label {
    clear: both;
    float: left;
    font-size: 1.2em;
    width: 80px;
    color: #333;
    font-weight: bold;
    height: 35px;
    line-height: 35px;
    margin-right: 10px;
}
	
input, textarea {
    color: #333;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 1.2em;
    float: left;
    border-radius: 5px;
    width: 320px;
    background: #fefefe;
    border: 1px solid #c4c4c4;
    padding: 10px;
    margin-bottom: 10px;
    transition: all 0.3s ease-in-out;
    box-shadow: 0 1px 0 0 #fff, inset 0 1px 4px 0 #ccc;
}
	
textarea {
    height: 60px;
    resize: none;
}
	
input:focus, textarea:focus {
    border: 1px solid #0cf;
    outline: none;
    box-shadow: 0 0 4px 1px #0cf;
}
	
/* -- Placeholder text -- */

/* chrome, safari */
::-webkit-input-placeholder {  
    color: #666!important;  
    font-style: italic;  
}  
  
/* mozilla */
input:-moz-placeholder, textarea:-moz-placeholder {  
    color: #666!important;  
    font-style: italic;  
}  
  
/* ie (faux placeholder) */
input.placeholder-text, textarea.placeholder-text  {  
    color: #666!important;  
    font-style: italic;  
}  
	
/* -- Select, checkbox and radio buttons (uses jQuery) -- */

/* Radio buttons and check boxes */

div.inputContainer {
    padding: 0 0 10px 0;
    display: block;
    overflow: hidden;
    clear: both;
    margin: 10px 0;
    border-bottom: 1px dotted #666;
}

div.inputContainer p {
    color: #333;
    margin: 0 0 10px 90px;
}
	
label.radioButton, label.checkBox {
    clear: none;
    float: left;
    font-weight: normal;
    line-height: 30px;
    width: auto;
    color: #666;
}
	
label.radioButton {
    height: 25px;
}

.checkbox, .radio {
    width: 30px;
    height: 30px;
    padding: 0 5px 0 0;
    background: url(../images/light-checkbox.png) no-repeat;
    display: block;
    clear: left;
    float: left;
    margin-left: 90px;
}

.radio {
    background: url(../images/light-radio.png) no-repeat;
    margin-bottom: 0;
    height: 25px;
}

/* select dropdown */

div.selectContainer {
    float: left;
}

.select {
    position: absolute;
    height: 21px;
    line-height: 21px;
    overflow: hidden;
    padding: 3px 30px 3px 10px;
    color: #333;
    font-size: 1.2em;
    float: left;
    border-radius: 5px;
    background: #f3f3f3 url(../images/light-selectarrow.gif) no-repeat 90% center;
    border: 1px solid #ccc;
    margin-bottom: 10px;
    width: 50px;
    box-shadow: inset 0 1px 0 0 #fff, 0 1px 4px 0 #ccc;
}
	
/* -- Required and error styles -- */
	
span.required {
    color: #0cf;
}
	
ul.errors {
    border-radius: 5px;
    font-size: 1.2em;
    padding: 10px 10px 10px 55px;
    color: #fff;
    margin-bottom: 10px;
    border: 1px solid #930;
    *height: 28px;
    min-height: 28px;
    text-shadow: 1px 1px 0 #900;
    background: url(../images/cross.png) no-repeat 1px 0, linear-gradient(#ff5a5a, #f00);
}
	
ul.errors li {
    margin-top: 5px;
    overflow: hidden;
}
	
ul.errors li:before {  
    content: ' - ';  
} 

ul.errors li.info {  
    font-weight: bold;
    margin-top: 0;
} 

ul.errors li.info:before {
    content: ' ';
}
	
p.success {
    border-radius: 5px;
    font-size: 1.2em;
    padding: 10px 10px 10px 55px;
    color: #fff;
    margin-bottom: 10px;
    border: 1px solid #390;
    height: 28px;
    line-height: 28px;
    text-shadow: 1px 1px 0 #360;
    background: url(../images/tick.png) no-repeat 1px 0, linear-gradient(#99d559, #6baf23);
}

/* Submit button */
	
input.submit {
    clear: both;
    margin-bottom: 0;
    cursor: pointer;
    width: auto;
    float: right;
    font-weight: bold;
    color: #333;
    border: 1px solid #09c;
    box-shadow: inset 0 1px 0 0 #fff, 0 1px 4px 0 #ccc;
    background: #0cf;
    transition: all 0.2s ease-in-out;
}
	
input.submit:hover {
    background-color: #4df;
}
	
input.submit:active {
    position: relative;  
    top: 1px; 
}
Posted in CSS3, Forms, HTML5, jQuery | Leave a comment

CSS3 text-shadow

Following on from my post on CSS3 box-shadow, we can also add shadows to text which will follow the shapes of the characters, not just outline the text element.

Offset shadow (solid)

CSS3 outer solid text-shadow

View demo

The markup

h1 {
    -webkit-text-shadow: 3px 3px 0 #999;
    -moz-text-shadow: 3px 3px 0 #999;
    text-shadow: 3px 3px 0 #999;
}

This markup would produce a solid outer shadow on an h1 heading, with the shadow offset 2 pixels from the left and 2 pixels from the top of the the element and no blur. The meanings of the three numbers are as follows:

  1. Horizontal offset
  2. Vertical offset
  3. Blur distance

Offset shadow (blurred)

This example has a 2 pixel blur applied.

CSS3 outer blurred text-shadow

View demo

The markup

h1 {
    -webkit-text-shadow: 3px 3px 2px #999;
    -moz-text-shadow: 3px 3px 2px #999;
    text-shadow: 3px 3px 2px #999;
}

Outlined text

We can make the text look like it has an outline by adding four shadows, each one offset slightly from one of the sides:

CSS3 text-shadow outline effect

View demo

The markup

h1 {
    -webkit-text-shadow: -1px 0 1px #000, 1px 0 1px #000, 0 -1px 1px #000, 0 1px 1px #000;
    -moz-text-shadow: -1px 0 1px #000, 1px 0 1px #000, 0 -1px 1px #000, 0 1px 1px #000;
    text-shadow: -1px 0 1px #000, 1px 0 1px #000, 0 -1px 1px #000, 0 1px 1px #000;
}

Multiple shadows

We can apply multiple shadows to a text element to create various effects. Here is an example using three different colours at various placements:

CSS3 multiple text-shadows

View demo

The markup

h1 {
    -webkit-text-shadow: 12px 12px 2px #f0c, 30px -3px 2px #f90, 6px -10px 2px #9f3;
    -moz-text-shadow: 12px 12px 2px #f0c, 30px -3px 2px #f90, 6px -10px 2px #9f3;
    text-shadow: 12px 12px 2px #f0c, 30px -3px 2px #f90, 6px -10px 2px #9f3;
}

Multiple shadows: outset effect

We can use multiple shadows to make the text looks like it has some relief to it. Here, we use two shadows; a lighter coloured slightly offset shadow at the top of the text, and another darker coloured one below:

CSS3 text-shadow outset effect

View demo

The markup

h1 {
    -webkit-text-shadow: -1px -1px #ffa2bc, 1px 1px #8a0030;
    -moz-text-shadow: -1px -1px #ffa2bc, 1px 1px #8a0030;
    text-shadow: -1px -1px #ffa2bc, 1px 1px #8a0030;
}

Multiple shadows: inset effect

Similarly, we can make the text look like it is inset into the background by reversing the shadows from the example above (darker colour on top, lighter colour on the bottom):

CSS3 text-shadow inset effect

View demo

The markup

h1 {
    -webkit-text-shadow: -1px -1px #8a0030, 1px 1px #ffa2bc;
    -moz-text-shadow: -1px -1px #8a0030, 1px 1px #ffa2bc;
    text-shadow: -1px -1px #8a0030, 1px 1px #ffa2bc;
}
Posted in CSS3 | Leave a comment

Prefix free

Prefix free logo

I discovered Prefix free the other day and think it is a genius idea! I find it a bit annoying to have to add in vendor prefixes -webkit-, -moz- and -o- for every CSS3 property I want to use, so in effect, adding each one in 3 times to get them to work in the most recent browsers. With this script, you can add the property without the prefixes into your stylesheet, and the script will detect which browser you are using to view the page and work behind the scenes to add on the prefixes required to view that effect.

For example, if you are viewing a page in Google Chrome, it would turn this:

div {   
    box-shadow: 0 0 5px 5px #999;
}

Into this:

div {   
    -webkit-box-shadow: 0 0 5px 5px #999;
}

To get it to work, follow these steps:

Posted in CSS3 | Leave a comment

CSS3 box-shadow

In CSS3, we can add shadows to objects without using images. We do need to add prefixes for Mozilla and Webkit browsers, so in effect adding the same styles 3 times (unless we use Prefix free).

We have quite a lot of options with how we create the shadows; they can be outset, inset (or both), and have multiple colours – all of which I’ll explore below.

Outer shadow

Here is how an outer shadow applied to an image tag appears via the medium of this yummy looking cupcake:

CSS3 outer box-shadow

View demo

The markup:

img {
    -webkit-box-shadow: 0px 0px 5px 3px #999;
    -moz-box-shadow: 0px 0px 5px 3px #999;
    box-shadow: 0px 0px 5px 3px #999;
}

This markup produces an outer shadow, with the shadow extending the same amount from every side of the element it is assigned to (in this case, an image). The meanings of the four numbers are as follows:

  1. Horizontal offset
  2. Vertical offset
  3. Blur distance
  4. Spread distance

Outer shadow (offset)

In the previous example, we didn’t add any values to make the shadow appear offset. Let’s see what happens when we do:

CSS3 outer offset box-shadow

View demo

Markup:

img {
    -webkit-box-shadow: 4px 4px 5px 3px #999;
    -moz-box-shadow: 4px 4px 5px 3px #999;
    box-shadow: 4px 4px 5px 3px #999;
}

Inner shadow

We can also make shadows appear to be inside of an element. I shall use a div as an example this time, as we may not be able to see the inside shadow with an image in the way:

CSS3 inner box-shadow

View demo

Markup:

div {
    -webkit-box-shadow: inset 0 0 5px 3px #999;
    -moz-box-shadow: inset 0 0 5px 3px #999;
    box-shadow: inset 0 0 5px 3px #999;
}

Inner and outer shadows on the same element

Multiple shadows can be applied to an element. Here is an example of when both inner and outer shadows are applied to a div. Each shadow is a slightly different colour (outer shadow is darker grey, inner shadow is lighter grey), so we can see them easier:

CSS3 inner and outer box-shadows on the same element

View demo

Markup:

div {
    -webkit-box-shadow: inset 2px 2px 4px 1px #ccc, 2px 2px 4px 1px #999;
    -moz-box-shadow: inset 2px 2px 4px 1px #ccc, 2px 2px 4px 1px #999;
    box-shadow: inset 2px 2px 4px 1px #ccc, 2px 2px 4px 1px #999;
}

Double shadows of the same type

We can’t just put two different types of shadows onto an object, we can also apply two shadows of the same type; for example, two inner shadows:

CSS3 double inner box-shadows on the same element

View demo

Markup:

div {
    -webkit-box-shadow: inset 2px 2px 4px 1px #ccc, inset -2px -2px 4px 1px #999;
    -moz-box-shadow: inset 2px 2px 4px 1px #ccc, inset -2px -2px 4px 1px #999;
    box-shadow: inset 2px 2px 4px 1px #ccc, inset -2px -2px 4px 1px #999;
}

Multiple coloured shadows

Shadows don’t even have to be only one colour. Here is an example of an outer shadow with no offset, with the shadow blending from purple to pink to orange:

Multiple coloured outer box-shadow

View demo

Markup:

div {
    -webkit-box-shadow: 0 0 4px 2px #90f, 0 0 4px 4px #f06, 0 0 4px 7px #f90;
    -moz-box-shadow: 0 0 4px 2px #90f, 0 0 4px 4px #f06, 0 0 4px 7px #f90;
    box-shadow: 0 0 4px 2px #90f, 0 0 4px 4px #f06, 0 0 4px 7px #f90;
}

What happens if I apply box-shadow to text?

This will happen – the shadow will follow the box shape of the text element (it won’t go around the characters):

Applying box-shadow to text

View demo

If this is what you want, fine, but if you want the shadow to follow the shapes of the characters, use text-shadow instead.

Posted in CSS3 | Leave a comment

HTML5 tags: new and recycled

Recycled tags

In HTML5, we see some familiar tags, but used in a different way to how they were originally intended. The following tags were originally designed for aesthetic purposes, but have been repurposed to fit the semantic aim of HTML5.

<small>

The <small> tag used to be used to decrease the size of text in pre-CSS days. In HTML5, it should be used for small print; for example, legal text or terms and conditions.

Markup:

<small>Insert text here</small>

Example:

This is a paragraph, consectetur adipiscing elit. Sed porta, sem nec molestie volutpat, diam nunc luctus orci, a imperdiet dui erat id mi. Integer dictum tortor id dolor sagittis id fermentum dolor euismod. Phasellus nibh sem, elementum eu semper eu, laoreet ut lacus. Curabitur gravida tortor eget urna imperdiet egestas gravida erat pharetra.

Smallprint text lorem ipsum dolor sit amet.

<b>

The <b> (bold) tag was originally used to increase the weight of text. It should now be used to highlight text that is styled differently to the main body of text, but has no extra importance.

Markup:

<b>Insert text here</b>

Example:

Highlighted text

The <strong> tag should instead be used to mark up text that has extra importance.

Markup:

<strong>Insert text here</strong>

Example:

Strong text

These two examples may look identical, but the aim of the tags is to provide more semantics to a document, so they have different practical uses.

<i>

The <i> (italic) tag was originally used to make text italic. In HTML5, it should be used to mark up text that has “an alternate voice or mood”.

Markup:

<i>Insert text here</i>

Example:

Alternate voice text

To add emphasis to a piece of text, the <em> tag should be used instead.

Markup:

<em>Insert text here</em>

Example:

Emphasised text

Again, these two examples may look identical, but they have different semantic uses, not stylistic ones.

<cite>

The <cite> (citation) tag has changed slightly; before, it was used to reference other sources, be that a person or another piece of work. In HTML5, it should only be used to reference the title of a work, not to reference people’s names.

Markup:

<cite>Insert text here</cite>

Example:

Referenced piece of work, consectetur adipiscing elit. Sed porta, sem nec molestie volutpat, diam nunc luctus orci, a imperdiet dui erat id mi. Integer dictum tortor id dolor sagittis id fermentum dolor euismod. Phasellus nibh sem, elementum eu semper eu, laoreet ut lacus. Curabitur gravida tortor eget urna imperdiet egestas gravida erat pharetra.

Reference Title

<a>

The <a> (link) tag hasn’t changed its function, but now we can place multiple elements within the tag, and they will all link to the source. We have always been able to do this in practice, but it hasn’t been valid. In HTML5 it is valid.

Markup:

<a href="linklocation">
    <p>This paragraph text links to the location</p>
    
    <img src="imagelocation.jpg" alt="This image also links to the location" />
</a>

New tags

Text-level elements

The elements listed below are elements which can be used inline on parts of text.

<mark>

This should be used to highlight the search term in a search result. It doesn’t add any importance to the word or phrase, just highlights it for the purpose of the search.

Markup:
<mark>Search term</mark>
Example:

Search results for ‘video game

  1. Video game – Wikipedia, the free encyclopedia
    A video game is an electronic game that involves human interaction with a user interface to generate visual feedback on a video device. The word video in video…
  2. Video Game Trailers for Wii, PSP, Xbox, PS3 & More | Upcoming…
    Watch new video game trailers, read reviews and previews of upcoming video games at GameTrailers.com. Video game demos, online gameplay, game cheats…

<time>

The <time> tag can be used to mark up dates and times.

Markup:
Time
<time datetime="09:00">9am</time>
Date
<time datetime="1984-03-16">16th March 1984</time>
Time and date
<time datetime="1984-03-16T09:00">9am on 16th March 1984</time>
No ‘datetime’ attribute; the value must be placed within the tags
<time>1984-03-16</time>

Sectioning content elements

HTML5 does away with the need to use divs for everything, and provides us with some semantic structural elements to use.

<section>

The <section> tag is used to group together related content. A section tag can (and should) contain header and footer elements if they are needed.

Markup:
<section>
    <header>Insert header content here.</header>

    <p>Insert main content here.</p>

    <footer>Insert footer content here.</footer>
</section>

<header>

The <header> is a place to put introductory elements for a page or section, e.g. title and main navigation. In HTML5, a page can have multiple header elements.

Markup:
<header>Insert header content here.</header>

<nav>

The <nav> tag was created as a container for navigation elements. The element can be placed within the header if needed, which is where I would usually put it. A list can then be added inside the element to display the links.

Markup:
<nav>
    <ul>
        <li><a href="#">Link 1</a></li>
        <li><a href="#">Link 2</a></li>
        <li><a href="#">Link 3</a></li>
    </ul>
</nav>
Example:

<footer>

The <footer> element, like the header, can be used for the entire HTML document and also within a section. It should contain information about its containing element, so for a page footer it would contain copyright information etc. and within a section, it could have additional information about the section content.

Markup:
<footer>Insert footer content here.</footer>

<aside>

The <aside> element should contain information that relates to the main content (for example, pullquotes) but is separate. If it is removed, it shouldn’t detriment the rest of the page.

Markup:
<aside>Insert aside content here.</aside>

<article>

The <article> element should be used for news articles, blog entries, comments; anything that is syndicated. It should also be used for self-contained widgets. An article is a specialised form of the section element, and it too can contain a header and a footer. Multiple articles can be contained within a section, and vice versa, and they can be nested inside other articles (the same can also be said for sections). ‘Pubdate’ can be added into the time tag in articles to highlight the date and time of publication.

Markup:
<article>
    <header>Insert header content here.</header>

    <p><time datetime="2011-12-19" pubdate></time>
    Insert main content here.</p>

    <footer>Insert footer content here.</footer>
</article>

<hgroup>

The <hgroup> element is used to group headings together. Only the first heading element will contribute to the document outline, so the second one is more of a tagline.

Markup:
<hgroup>
    <h1>Insert main header title here.</h1>
    <h2>Insert tagline here.</h2>
</hgroup>
Posted in HTML5 | Leave a comment

HTML5 video

Default video player controls

Video players can be added to an HTML document. The default view for the player in different browsers is as follows:

Default HTML5 video player views in Safari, Firefox, Google Chrome and Internet Explorer

View demo

Markup

To add video to a page, the markup should look as follows:

<video controls preload="auto" width="360" height="240" poster="previewimage.gif">
    <source src="videofile.webm" type="video/webm" />
    <source src="videofile.ogv" type="video/ogg" />
    <source src="videofile.mp4" type="video/mp4" />
    <object type="application/x-shockwave-flash" width="360"height="240" data="player.swf?file=videofile.mp4">
        <param name="movie" value="player.swf?file=videofile.mp4" />
    </object>
    <a href="videofile.mp4">Download video clip</a>
</video>

Video tag attributes

Various attributes can be added into the video tag:

  • controls: Playback controls for the video are displayed.
  • width=“number” and height=“number: The width and height of the video can be set here.
    Note: the video will retain its aspect ratio. This is especially evident in IE, where the video will become letterboxed if the size isn’t set correctly. Either just width or just height can be used, and the other dimension will adjust accordingly
  • autoplay: The video plays upon page load without any input from the user.
  • loop: The video plays endlessly.
  • poster=“previewimage.gif: A preview image can be inserted to be shown before the video is played.
  • preload=“value: Values in the quotes can be none, auto or metadata. none ensures that the video isn’t preloaded, auto ensures that the video is preloaded, and if metadata is added, only the metadata of the video is loaded.
    Note: In IE9, the preview image won’t show if preload is set.

File formats for different browsers

So that the video will work in multiple browsers, the following filetypes must be added as sources within the video tags:

  • .webm file, which will work in Firefox 4, Google Chrome and Opera 10.6.
  • .ogv file, which will work in Firefox, Opera and Chrome.
  • .mp4 file, which will work in Firefox and IE9.
  • .mp4 file for IE8, which needs to be supplied via Flash.
  • A link to the video file can be provided as a last resort after the source declarations, and any browsers that don’t support the audio content will show the link instead. Similarly, a text transcript can be placed here.
  • Video files can be converted with Miro Video Converter.

Video player with custom controls

By interacting with the media API with Javascript, we can style up the buttons in a different way to the default player. Here is a very simple example using styled links:

HTML5 video player with custom controls

View demo

Markup

<video id="videoPlayer" preload="auto" width="360" height="240" poster="images/previewimage.gif">
    <source src="videofile.webm" type="video/webm" />
    <source src="videofile.ogv" type="video/ogg" />
    <source src="videofile.mp4" type="video/mp4" />
    <object type="application/x-shockwave-flash" width="360"height="240" data="player.swf?file=videofile.mp4">
        <param name="movie" value="player.swf?file=videofile.mp4" />
    </object>
    <a href="videofile.mp4">Download video clip</a>
</video>
                
<div>
    <a onClick="document.getElementById('videoPlayer').play()">Play</a>
    <a onClick="document.getElementById('videoPlayer').pause()">Pause</a>
</div>

The video player can be styled!

Unlike with a Flash plugin, we can add styles to the video player, so we can style it using CSS. Here is an example using CSS3 rotate and skew:

Styled HTML5 video player

View demo

Video player using jPlayer

jPlayer is a jQuery plugin, which does pretty much all the hard work for us, and lets us skin the video player however we want (view the demo source to see how this was integrated). Here is my styled version:

HTML5 video player using jPlayer

View demo

Posted in HTML5 | Tagged , | 1 Comment

HTML5 audio

Default audio player controls

A simple audio player can be added to an HTML document. The default view for the player in different browsers is as follows:

Default HTML5 audio player views in Safari, Firefox, Google Chrome and Internet Explorer

View demo

Markup

To add audio to a page, the markup should look as follows:

<audio controls preload="auto">
    <source src="media/soundfile.ogg" type="audio/ogg" />
    <source src="media/soundfile.mp3" type="audio/mpeg" />
    <object type="application/x-shockwave-flash" data="player.swf?soundFile=media/soundfile.mpg">
        <param name="movie" value="player.swf?soundFile=media/soundfile.mpg" />
    </object>
    <a href="media/soundfile.mp3">Download audio clip</a>
</audio>

Audio tag attributes

Various attributes can be added into the audio tag:

  • controls: Playback controls for the audio are displayed.
  • autoplay: The audio plays upon page load without any input from the user.
  • loop: The audio plays endlessly.
  • preload=“value”: Values in the quotes can be none, auto or metadata. none ensures that the audio isn’t preloaded, auto ensures that the audio is preloaded, and if metadata is added, only the metadata of the audio is loaded.

File formats for different browsers

So that the sound will work in multiple browsers, the following must be added as sources within the audio tags:

  • .ogg file, which will work in Firefox.
  • .mp3 file, which will work in Safari.
  • .mpg file for IE, which needs to be supplied via Flash.
  • A link to the audio file can be provided as a last resort after the source declarations, and any browsers that don’t support the audio content will show the link instead. Similarly, a text transcript can be placed here.
  • Sound files can be converted at media.io.

Audio player with custom controls

By interacting with the audio API with Javascript, we can style up the buttons in a different way to the default player. Here is a very simple example using styled links:

HTML5 audio player with custom controls

View demo

Markup

<audio id="audioPlayer" preload="auto">
    <source src="soundfile.ogg" type="audio/ogg" />
    <source src="soundfile.mp3" type="audio/mpeg" />
    <object type="application/x-shockwave-flash" data="player.swf?soundFile=soundfile.mpg">
        <param name="movie" value="player.swf?soundFile=soundfile.mpg" />
    </object>
    <a href="soundfile.mp3">Download audio clip</a>
</audio>
                
<div>
    <a onClick="document.getElementById('audioPlayer').play()">Play</a>
    <a onClick="document.getElementById('audioPlayer').pause()">Pause</a>
    <a onClick="document.getElementById('audioPlayer').volume+= 0.1">Volume up</a>
    <a onClick="document.getElementById('audioPlayer').volume-= 0.1">Volume down</a>
</div>

Audio player using jPlayer

jPlayer is a jQuery plugin, which does pretty much all the hard work for us, and lets us skin the audio player however we want (view the demo source to see how this was integrated). Here is my styled version:

HTML5 audio player using jPlayer

View demo

Posted in HTML5 | Tagged , | Leave a comment

HTML5 base template

Here is a base HTML5 template to copy and paste for any new project. Here is a quick summary:

  • HTML5 doctype, character set and css/script references are used (shortened from XHTML)
  • References to Modernizr and jQuery
  • All script references are located at the bottom of the markup (apart from Modernizr, which stays at the top so it is loaded first)
  • Divs aren’t used for the main page structure; ‘header’, ‘footer’, ‘aside’ and ‘section’ are used instead
  • An unordered list inside the ‘nav’ element acts as the main navigation
  • The main content contains its own header and footer, with the bulk of the content to be placed within the ‘article’ tag
  • The ‘aside’ tag can be used to hold text, images or quotes related to the main content of the page.
<!DOCTYPE HTML>
<html lang="en" class="no-js">
<head>
    <meta charset="utf-8" />
    <title>Page title</title>
    
    <meta name="description" content="Page description" />
    
    <link href="favicon.ico" rel="shortcut icon" />
    
    <link href="css/styles.css" rel="stylesheet" media="screen" />
    <link href="css/print.css" rel="stylesheet" media="print" />
	
    <script src="js/modernizr-2.0.6.min.js"></script>
</head>
<body>
    <header>
    	<hgroup>
        	<h1>Page title</h1>
        	<h2>Tagline</h2>
        </hgroup>
        
        <nav>
            <ul>
            	<li><a href="#">Nav item 1</a></li>
                <li><a href="#">Nav item 2</a></li>
                <li><a href="#">Nav item 3</a></li>
            </ul>
        </nav>
    </header>
    
    <section>
    	<header>
        	<h1>Page Title</h1>
        </header>
    		
        <p>Main content</p>
        
        <footer></footer>
    </section>
    
    <aside>
    	<h2>Aside title</h2>
        
        <p>Aside content</p>
    </aside>
	
    <footer>
    	<p>&copy; 2011</p>
    </footer>
    
    <script src="js/jquery-1.7.1.min.js"></script>
	<script></script>
    
    <!-- Insert Google Analytics code here -->
</body>
</html>
Posted in HTML5 | Tagged | Leave a comment