2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 587d7790367417b2b2512ab1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Use tabindex to Specify the Order of Keyboard Focus for Several Elements
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								challengeType: 0
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								videoUrl: 'https://scrimba.com/c/cmzRRcb'
							 
						 
					
						
							
								
									
										
										
										
											2019-08-05 09:17:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								forumTopicId: 301028
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								dashedName: use-tabindex-to-specify-the-order-of-keyboard-focus-for-several-elements
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --description--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-10 18:00:03 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `tabindex`  attribute also specifies the exact tab order of elements. This is achieved when the attribute's value is set to a positive number of 1 or higher.
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Setting a `tabindex="1"`  will bring keyboard focus to that element first. Then it cycles through the sequence of specified `tabindex`  values (2, 3, etc.), before moving to default and `tabindex="0"`  items.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								It's important to note that when the tab order is set this way, it overrides the default order (which uses the HTML source). This may confuse users who are expecting to start navigation from the top of the page. This technique may be necessary in some circumstances, but in terms of accessibility, take care before applying it.
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								Here's an example:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-19 00:24:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  tabindex = "1" > I get keyboard focus, and I get it first!< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-03-19 00:24:09 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  tabindex = "2" > I get keyboard focus, and I get it second!< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --instructions--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-01 11:56:07 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Camper Cat has a search field on his Inspirational Quotes page that he plans to position in the upper right corner with CSS. He wants the search `input`  and submit `input`  form controls to be the first two items in the tab order. Add a `tabindex`  attribute set to `1`  to the `search`  `input` , and a `tabindex`  attribute set to `2`  to the `submit`  `input` .
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-26 14:25:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Another thing to note is that some browsers may place you in the middle of your tab order when an element is clicked. An element has been added to the page that ensures you will always start at the beginning of your tab order.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --hints--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-01 11:56:07 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Your code should add a `tabindex`  attribute to the `search`  `input`  tag.
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert($('#search ').attr('tabindex'));
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-01 11:56:07 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Your code should add a `tabindex`  attribute to the `submit`  `input`  tag.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert($('#submit ').attr('tabindex'));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-01 11:56:07 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Your code should set the `tabindex`  attribute on the `search`  `input`  tag to a value of 1.
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert($('#search ').attr('tabindex') == '1');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-01 11:56:07 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Your code should set the `tabindex`  attribute on the `submit`  `input`  tag to a value of 2.
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert($('#submit ').attr('tabindex') == '2');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --seed--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## --seed-contents--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< body >  
						 
					
						
							
								
									
										
										
										
											2021-04-26 14:25:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < div  tabindex = "1"  class = "overlay" > < / div > 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  < header > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < h1 > Even Deeper Thoughts with Master Camper Cat< / h1 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < nav > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < ul > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < li > < a  href = "" > Home< / a > < / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < li > < a  href = "" > Blog< / a > < / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < li > < a  href = "" > Training< / a > < / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < / ul > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / nav > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / header > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < form > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label  for = "search" > Search:< / label > 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    < input  type = "search"  name = "search"  id = "search" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < input  type = "submit"  name = "submit"  value = "Submit"  id = "submit" > 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  < / form > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < h2 > Inspirational Quotes< / h2 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < blockquote > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < p > “ There's no Theory of Evolution, just a list of creatures I've allowed to live.” < br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    -  Chuck Norris</ p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / blockquote > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < blockquote > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < p > “ Wise men say forgiveness is divine, but never pay full price for late pizza.” < br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    -  TMNT</ p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / blockquote > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < footer > ©  2018 Camper Cat< / footer > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / body >  
						 
					
						
							
								
									
										
										
										
											2021-04-26 14:25:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  body {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    height: 100%;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    margin: 0 !important;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    padding: 8px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  .overlay {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    margin: -8px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    position: absolute;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    width: 100%;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    height: 100%;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --solutions--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-24 09:42:46 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< body >  
						 
					
						
							
								
									
										
										
										
											2021-04-26 14:25:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < div  tabindex = "1"  class = "overlay" > < / div > 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-24 09:42:46 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < header > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < h1 > Even Deeper Thoughts with Master Camper Cat< / h1 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < nav > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < ul > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < li > < a  href = "" > Home< / a > < / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < li > < a  href = "" > Blog< / a > < / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        < li > < a  href = "" > Training< / a > < / li > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      < / ul > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < / nav > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / header > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < form > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < label  for = "search" > Search:< / label > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < input  tabindex = "1"  type = "search"  name = "search"  id = "search" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < input  tabindex = "2"  type = "submit"  name = "submit"  value = "Submit"  id = "submit" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / form > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < h2 > Inspirational Quotes< / h2 > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < blockquote > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < p > “ There's no Theory of Evolution, just a list of creatures I've allowed to live.” < br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    -  Chuck Norris</ p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / blockquote > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < blockquote > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    < p > “ Wise men say forgiveness is divine, but never pay full price for late pizza.” < br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    -  TMNT</ p > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / blockquote > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < footer > ©  2018 Camper Cat< / footer > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / body >  
						 
					
						
							
								
									
										
										
										
											2021-04-26 14:25:28 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< style >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  body {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    height: 100%;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    margin: 0 !important;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    padding: 8px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  .overlay {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    margin: -8px;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    position: absolute;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    width: 100%;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    height: 100%;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / style >  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```