General

Intro to Google DevTools: Elements Panel

William Hutt
6 min read
ElementsPanel
This article was written over 18 months ago and may contain information that is out of date. Some content may still be relevant, but please refer to official documentation for the latest information.

Intro to Google DevTools: Elements Panel Today's article will give an overview of the Elements panel in Google DevTools. The Elements panel allows you to perform a number of cool things. It gives you access to things like a specific node and allows you to tweak and change that node. We’ll cover how to inspect a node, change a node, update and add styles to a node.

Inspecting a DOM node So we’re going to start by going to a site and right clicking and selecting the inspect option. This will bring up the Elements panel, and show us the DOM node for the object we’ve decided to inspect.

picture1

We can also search for a particular DOM node. After inspecting, I want to find the DOM node for the header “Grand Heroes Gacha Banner”. I’ll start by clicking CTRL+F, which will bring up a search bar on the Elements panel. I will then type in Grand Heroes Gacha Banner and this will give me the matches. These matches will then be highlighted in yellow.

picture2

Changing a DOM node Now that we have the DOM node selected, we’re going to edit it and change some things. First we’re going to edit the text from 1 Roll to One Roll by double clicking on 1 Roll. As you can see below this will be updated immediately and we can see the change on the website.

picture3

Then, we’re going to edit the node type. So first, I’m going to click on the newly changed One Roll. This triggers an event, and gives us some text. At this point, I’m going to inspect the item name. Now that we can see the DOM node in the Elements panel, I’ll right click it, and click edit as HTML. I’m going to change it to a list. Just like before, this will be updated immediately, and we can see the change on the website.

picture4

Updating DOM node styles This will be very similar to changing a DOM node. This time, we’ll be focusing on the css and style of the DOM we select. I’ll inspect the One Roll button again, but this time, look to the styles of the right side of the Elements panel.

picture5

After doing this, you can see all of the style information for the One Roll button. We’re going to start by editing the background color of the button. I will start by left clicking the background-color, and changing it to red. I will also do the same for the border-color. You will see that the color updates immediately, and changes from the light blue to a red.

picture6

Now, for another example, I will also update the buttons style to make it larger. I will do this by changing the padding of the button which is 6 x 12, but first I want to check out the dimensions of the button. To do this, I will scroll to the bottom of the style tab until I see a dimension box.

picture7

This box is very useful as it will give you the margin, border, padding, width, and height of the item selected. As you can see, the box is color coded, and when you hover over the different colors, it is reflected on the node you have selected.

I’m going to double it from 6 x 12 to 12 x 24. As a result, the button will double in size and update to reflect this.

picture8

Adding DOM node styles This is going to be similar to updating the node style, but this time we’ll, be adding our changes to the element.style {} area. picture9

After clicking the One Roll button and getting more text down below, we’ll inspect the item name. Now, we’ll navigate over to the styles, and go into the element.style {} area mentioned above. In this area, I want to add font-size: 2em to increase the size of the item name.

picture10

We can also change the color, so I’ll also add in color: red to update it from black to red.

picture11

Conclusion Today's article covered an overview of the Elements panel in Google DevTools. Hopefully, after reading this, you will have learned something new and useful. I personally find the Elements panel to be extremely helpful. I use it frequently when wanting to test out new ideas for layouts and styles before putting it into an IDE.

About the author

William Hutt

William Hutt

Software Engineer

I'm a software engineer with an interest in web development.

Keep reading

View all posts →

CSS Container Queries, what are they?

In this blog post, we take a look at container queries, a new feature that makes designing websites easier and more flexible. ...

Jesús Padrón6 mins
CSS

An example-based guide to CSS Cascade Layers

CSS Cascade Layers make style management simple—see how in this example-driven guide....

Dane Grant4 mins
CSS

Understanding the Difference Between `:focus` and `:focus-visible` in CSS

Understanding the Difference Between :focus and :focus visible in CSS I have learned my fair share about the importance of keyboard accessibility, so I know that visual indication of the focused element is very important. But the well known :focus pseudo class is not always the best fit for this job. That's where :focus visible comes in. Let's look at the differences between these two pseudo classes and explore the best practices for using them effectively. What is the :focus Pseudo Class? The :focus pseudo class is a CSS selector that applies styles to any element that receives focus, regardless of how that focus was triggered. This includes focus events from keyboard navigation, mouse clicks, and touch interactions. Example Usage of :focus In this example, the button will display a blue outline whenever it is focused, whether the user clicks on it with a mouse, taps it on a touchscreen, or navigates to it using the keyboard. What is the :focus visible Pseudo Class? The :focus visible pseudo class is more specialized. It only applies styles to an element when the browser determines that the focus should be visible. This typically occurs when the user navigates via the keyboard or assistive technologies rather than through mouse or touch input. Example Usage of :focus visible Here, the button will only show a blue outline when focused through keyboard navigation or another input method that usually requires visible focus indicators. Key Differences Between :focus and :focus visible :focus Behavior: Applies to any element that receives focus, regardless of the input method. Use Cases: Ensures that all interactions with the element are visually indicated, whether by mouse, keyboard, or touch. :focus visible Behavior: Applies styles only when the focus should be visible, such as using a keyboard or assistive technology. Use Cases: Ideal for scenarios where you want to provide focus indicators only to keyboard and assistive technology users while avoiding unnecessary outlines for mouse and touch users, typically required by design. Accessibility Implications :focus Pros: Guarantees that all users can see when an element is focused, which is critical for accessibility. Cons: Can lead to a suboptimal experience for mouse users, as focus styles may appear unnecessarily during mouse interactions. :focus visible Pros: Enhances user experience by showing focus indicators only when necessary, thus keeping the interface clean for mouse and touch users. Tailors the experience for keyboard and assistive technology users, providing them with clear visual cues. Cons: Additional considerations may be required to ensure that focus indicators are not accidentally omitted, especially in older browsers that do not support :focus visible. There may be cases where you want to show focus indicators for all users, regardless of input method. Best Practices for Using :focus and :focus visible To achieve the best accessibility and user experience, combining both :focus and :focus visible in your CSS is often a good idea. Combining :focus and :focus visible Here is a Stackblitz example of what such styling could look like for you to try out and play with. Additional Tips Test with Keyboard and Assistive Technology: Ensure that your web application is navigable using a keyboard (Tab, Shift + Tab, etc.) and that focus indicators are visible for those who rely on them. It's never a bad idea to include accessibility testing in your e2e testing suite. Provide Clear Focus Indicators: Make sure that focus indicators are prominent and easy to see. A subtle or hard to spot focus indicator can severely impact accessibility for users who rely on keyboard navigation. Conclusion The :focus visible pseudo class offers a more refined way to manage focus indicators, improving accessibility and user experience, particularly for keyboard and assistive technology users. By understanding the differences between :focus and :focus visible, and applying best practices in your CSS, you can create more accessible and user friendly web applications. Remember, accessibility should never be an afterthought. By thoughtfully applying focus styles, you ensure that all users, regardless of how they interact with your site, can easily navigate and interact....

Jan Kaiser3 mins
AccessibilityCSSPlaywright

The HTML Dialog Element: Enhancing Accessibility and Ease of Use

The new dialog element streamlines the implementation of accessible dialogs, modals, and other kinds of non-modal dialogs....

Jamie Kuppens4 mins
HTMLJavaScript