<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Karl Rixon &#187; CSS</title>
	<atom:link href="http://www.karlrixon.co.uk/articles/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.karlrixon.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 14 Jul 2010 08:54:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Remove Button Focus Outline Using CSS</title>
		<link>http://www.karlrixon.co.uk/articles/css/remove-button-focus-outline-using-css/</link>
		<comments>http://www.karlrixon.co.uk/articles/css/remove-button-focus-outline-using-css/#comments</comments>
		<pubDate>Fri, 08 May 2009 23:03:42 +0000</pubDate>
		<dc:creator>Karl</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.karlrixon.co.uk/?p=68</guid>
		<description><![CDATA[If you've ever tried to style or remove the focus outline on HTML buttons you may have found it impossible with just CSS. This article demonstrates how it can be done in Gecko based browsers.]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>Alot of people will use the outline CSS property to get rid of the focus outline around links using something like this:</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>However one thing you may have noticed if you&#8217;ve ever tried this is that it has no effect on the focus border of buttons:</p>
<p><img src="http://www.karlrixon.co.uk/wp-content/uploads/2009/05/button_focus.png" alt="Button with a focus outline" title="button_focus" width="117" height="67" class="size-full wp-image-69" /></p>
<p>It is possible to remove (or style) this border, although be aware that it only works in Gecko based browsers (As far as I know &#8211; it&#8217;s certainly possible webkit has something similar now. Don&#8217;t hold your breath for IE though!).</p>
<h3>The Method</h3>
<p>The way to achieve this is to use the propriety mozilla pseudo-class ::-moz-focus-inner. This targets the focus outline and allows it to be styled. Note that it is the border property not the outline property which handles the style of the outline itself.</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">button<span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;reset&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;button&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;file&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;button&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner </span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>The ugly black border is banished:</p>
<p><img src="http://www.karlrixon.co.uk/wp-content/uploads/2009/05/button_nofocus.png" alt="The same button with the CSS applied" title="button_nofocus" width="117" height="67" class="size-full wp-image-70" /></p>
<p>To style the border rather than remove it completely, a more accessible solution, you can use more standard pseudo-classes such as :focus and apply some normal CSS rules:</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">button<span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;reset&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;button&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;file&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;button&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner </span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">dotted</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
button<span style="color: #3333ff;">:focus</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;reset&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:focus</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;button&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:focus</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:focus</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span><br />
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;file&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;button&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:focus</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner </span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#F3F3F3</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<h3>A Note on Accessibility</h3>
<p>I&#8217;m going to end this post with a word about accessibility. The technique described here is not very friendly to people using a keyboard to navigate the site either by choice or due to a disability. Personally I believe that accessibility and design need to work together as much as possible, and this is not something I would use on a public site. However I believe that in some situations, it is perfectly acceptable to sacrifice accessibility over design.</p>
<p>At my place of work for example, I develop and maintain a CMS which I am in the process of redeveloping/redesigning. I also have control over the user&#8217;s computers and the software on them, including the browser. Because I know the audience of the site, and know what browser they will be using as well as the fact that they will not be adversly affected by this, I made the design decision to use this technique. If you don&#8217;t know your audience this well I&#8217;d urge you to consider taking the hit on the design for the sake of users who might be affected by the lack of button focus indication.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.karlrixon.co.uk/articles/css/remove-button-focus-outline-using-css/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
