Source code of the page hotkeys. Google Chrome - tools for webmasters
So, today we will look at several useful tools for Web masters that make life easier when designing a website. Let's start with the console for the web master in Google Chrome. And let’s go through the questions that most often arise for a webmaster during website layout.
To get to the console, open your website in Google Chrome, right-click anywhere on the web page, and select “View page code” in the contextual drop-down menu, or on a specific element to study by selecting “View code” element".
At the top you will have several tabs listed. Today we will talk about the “Elements” tab , which presents the elements of a web page with highlighting of tags, properties, highlighting the nesting of elements, a representation of the element’s hierarchy in the DOM tree (a hint at the bottom, from the root parent to the current one), the ability to edit elements, a list of their properties, consider searching by elements, as well as Let's get acquainted with viewing css styles, etc., associated with elements.
How can I view all the styles that are associated with a specific element? Which one is used now? In what files are they located?
So, nothing could be easier! Open the Google Chrome browser, open our site - the source of the questions, right-click on the desired element if it is visible in the context of the page, and select “View element code” in the context menu.
At the bottom we have a console with a highlighted tab on the left “ Elements" and all the styles associated with the element on the right, where: Computed Styles– these are general “summary” styles that were assigned to the element from the css rules and settings of the user’s browser (his environment), and at the same time the tab is collapsed.
But we are interested in the “Styles” tab, expanded under it, which lists in turn all the styles assigned to the element, as well as files where these rules are specified for this element by its type, id, class, name, property, attribute, etc. . Moreover, if a css rule is crossed out, it means it was redefined earlier/later (which makes it easy to track which of the css rules has priority and is applied in this case to the element).
Below the console there is a line that shows the element in the document hierarchy, easily allowing you to view the entire list of parent elements from the root to the selected element. Something like “bread crumbs”.
Html tag not visible in the context of the page? Or do you need to find all tags, for example, by a specific class, name, property, type?
Open the site in Google Chrome, right-click, call up the context menu, select « View page code » . Press the key combination “CTRL + F” at the same time, enter the phrase we need ( For example: class=”padding") and move through the list of found results, simultaneously viewing all the styles associated with the desired elements on the right side of the page.
How to view the html code of an element(s) loaded dynamically (for example: via Ajax)
We are waiting for the page to load in Google Chrome. We perform the necessary actions for Ajax to work. Right-click on the loaded data, select “View element code” in the context menu, and examine the result in the console on the “Elements" tab on the left.
View css style changes in real time
By the way, it is also convenient to observe, if necessary, what styles are assigned to an element on the fly, for example, when scrolling through a gallery and other timer events. All styles assigned via javascript in real time will be displayed in the property style selected element in the window on the “Elements” tab.
Interactively view the impact of css rules on the presentation of html tags
Google Chrome provides an interactive console for css styles. This means that you can not only view which styles are applied to the element, but also move the mouse cursor over a specific css property, enable it using the pop-up checkbox on the right, or disable it by clearing the flag, and view the resulting result on the page.
We change the structure of presentation of html elements on the fly (directly in the browser)
So, we have already learned how to explore the structure of a web document in Google Chrome, now we will briefly look at editing elements on the fly. We go to the console in any way convenient for us. We find the desired element in the “Elements” tab, right-click on it, thereby calling up the pop-up context menu:
- Add attribute– adds an attribute for the specified element. As soon as the cursor becomes active, we begin to set the desired property. For example: write name="itemImage", which will be immediately added to our element.
- Edit attribute– if you right-click on an element attribute, the item becomes available editattribute. Click and edit.
Usage example: We forgot the password saved under asterisks in Google Chrome (if the password was saved in this browser). Right-click on the element with the password entered, click on “View Element Code” , in the console on the left tab Elements right-click on the type="password" attribute, left-click on Editattribute change the attribute type=”password" on type=”text", and now, instead of asterisks, the same password is displayed in text form.
- Edithtml– right-click on the element in the console Elements, select Edithtml, change the code to your liking.
- CopyasHTML– we copy the portion of HTML we need for further research, say, in a notepad, or for other purposes where we need to apply exactly the same layout. We save time.
- CopyXPATH– copies the XPATH representation of the structure from the root of the parent element to the selected element.
- Deletenode– if you need to remove the currently selected element and all its children from the context of the web page, and see the result.
- Wordwrap– will render a web page view in the console context Elements more readable.
In the following articles we will continue to consider tools for webmasters, and in particular we will get acquainted with the remaining tabs of tools for webmasters in Google Chrome, and also consider debugging javascript errors using different browsers
If you open any web page, it will contain typical elements that do not change depending on the type and focus of the site. Example 4.1 shows the code for a simple document containing basic tags.
Example 4.1. Web page source code
Heading
First paragraph.
Second paragraph.
Copy the contents of this example and save it in the c:\www\ folder as example41.html. After that, launch the browser and open the file through the menu item File > Open File (Ctrl+O). In the document selection dialog, select the file example41.html. The web page shown in Fig. 1 will open in the browser. 4.1.
Rice. 4.1. Result of running the example
Elementis intended to indicate the type of the current document - DTD (document type definition, description of the document type). This is necessary so that the browser understands how to interpret the current web page, because HTML exists in several versions, in addition, there is XHTML (EXtensible HyperText Markup Language), which is similar to HTML, but differs from it in syntax. So that the browser “does not get confused” and understands according to which standard to display the web page, it is necessary to set in the first line of code .
There are several types, they differ depending on the version of HTML they are targeting. In table 4.1. The main types of documents with their descriptions are given.
DOCTYPE | Description |
---|---|
HTML 4.01 | |
Strict HTML syntax. | |
Transitional HTML syntax. | |
An HTML document uses frames. | |
HTML 5 | |
This version of HTML has only one doctype. | |
XHTML 1.0 | |
Strict XHTML syntax. | |
XHTML Transitional Syntax. | |
The document is written in XHTML and contains frames. | |
XHTML 1.1 | |
The developers of XHTML 1.1 expect it to gradually replace HTML. As you can see, this definition has no division into types, since the syntax is the same and obeys clear rules. |
The difference between a strict and transitional document description is a different approach to writing document code. Strict HTML requires strict adherence to the HTML specification and is unforgiving. Transitional HTML is more relaxed about some code flaws, so this type is preferable to use in certain cases.
For example, in strict HTML and XHTML the presence of the tag is required
In the future we will mainly use strict, unless otherwise specified. This will allow us to avoid common mistakes and teach us to write syntactically correct code.
You can often find HTML code without using any, the web page will still be shown in this case. However, it may happen that the same document appears differently in the browser when you useand without it. In addition, browsers can display such documents in their own way, as a result the page “crumbles”, i.e. will be displayed completely differently from what the developer requires. To avoid such situations, always addto the beginning of the document.
Tag defines the beginning of the HTML file, the header is stored inside it (
) and document body (Document title, also called a block
, can contain text and tags, but the content of this section is not directly shown on the page, except in the container
Tag is universal and adds a whole class of capabilities, in particular, with the help of meta tags, as this tag is generally called, you can change the page encoding, add keywords, document description and much more. So that the browser understands that it is dealing with UTF-8 encoding (Unicode transformation format, Unicode transformation format) and this line is added.
Tag
Rice. 4.2. Header view in browser
Tag
You must add a closing tag to indicate that the document title block is complete.
Document body
Heading
HTML offers six text headings at varying levels, which indicate the relative importance of the section following the heading. Yes, tag
represents the most important first level heading, and the tag serves to indicate the sixth level heading and is the least significant. By default, the first level heading is displayed in the largest bold font, and subsequent level headings are smaller in size. Tags ...Refer to block elements, they always start on a new line, and after them, other elements appear on the next line. Additionally, white space is added before and after the title.
...Refer to block elements, they always start on a new line, and after them, other elements appear on the next line. Additionally, white space is added before and after the title.
Some text can be hidden from being shown in the browser by making it a comment. Although this text will not be seen by the user, it will still be transmitted in the document, so if you look at the source code, you can discover hidden notes.
You need to quickly see all the changes on the site itself, without affecting the files and code of the site posted on the Internet. For example, change the color scheme of a block, move an element that has moved out, etc.
To do this, many webmasters use local Denwer or OpenServer servers, running a full copy of the site on their computer. This method is universal and suitable for professionals; it can be used to test the operation of various scripts and plugins, experiment with changing the design and edit all site files, and after the test, transfer the appropriate changes directly to the site.
For users who are far from webmaster art, I recommend using a browser for these purposes. Since I use Chrome, I will provide instructions with screenshots for this particular browser. By analogy, you can work with Opera, Yandex.Browser, Mozilla Firefox and other browsers; the principle of their tools is similar.
Instruction 1: how to view the entire HTML code of a site in a browser
Open the required web page of your site. Right-click on the required element, a browser contextual drop-down menu with available commands will appear:
Figure 1. Viewing the entire HTML code of a web page in the Chrome browser
Important: The commands in the drop-down menu may differ, for example, for active elements (links, pictures, videos) and inactive ones (text, background, divs):
Figure 2. Chrome browser drop-down menu
So if you don't find the command you need, just right-click somewhere else or use your browser's hotkeys.
Let's return to Figure 1, it shows the necessary command to view all the HTML code of the source web page, it is called " View page code". Click on the command, a new tab will open with the full code of the source web page, a big plus to everything - viewing is available with syntax highlighting:
Figure 3. Code fragment of this site
This tool is very useful for finding and editing the elements you are looking for.
Alternative ways to view all HTML code of a web page
For faster access, you can use other ways to call this tool
- In Figure 1 we also see that this command is available via a keyboard shortcut
+ ; - Paste view-source:site into the address bar of the browser instead of my domain, insert your address;
Both methods are universal and should work in all browsers.
At first, some may think that this is not a necessary tool at all, but viewing the entire HTML code of a site is great for finding the necessary elements in the code, these can be links, tags, meta tags, attributes and other elements.
Hotkey combination
Figure 3. Search by site code
After you enter a request into the search form, the screen will move to the first element found, using the arrows you can move between them and select the one you need:
Figure 4. Search by HTML site code
Instruction 2: how to view and edit the HTML and CSS code of a site in the Google Chrome browser
Now the most important part, in which I will show how you can edit the HTML and CSS code of a website in a browser. then transfer the changes to the browser.
![](https://i1.wp.com/samsebewebmaster.ru/wp-content/uploads/2015/12/%D0%9A%D0%BE%D0%BC%D0%B0%D0%BD%D0%B4%D0%B0-%D0%9F%D1%80%D0%BE%D1%81%D0%BC%D0%BE%D1%82%D1%80%D0%B5%D1%82%D1%8C-%D0%BA%D0%BE%D0%B4.jpg)
This useful tool is always available in your browser; experiment with other commands that will make it easier for you to edit your site.
" The same item is also in the context menu, which, if you right-click the text pages. You can also use the keyboard shortcut CTRL + U. Mozilla FireFox does not use external programs - original code pages with syntax highlighting will be opened in a separate browser window.
In Internet Explorer, click the File menu and select Edit in Notepad. Instead of the name Notepad, another name may be written, you have assigned it in the browser settings to view the original code A. On click pages with the right mouse button, a context menu appears, which also has an item that allows you to open the source code pages in an external program - “View HTML- code A".
In the Opera browser, open the menu, go to the “Page” section and you will have the opportunity to select “Source” in the “Development Tools” subsection code"or the item "Original code frame." These selections are assigned the hotkeys CTRL + U and CTRL + SHIFT + U, respectively. In a context menu bound to a click pages right-click, there is also an item “Initial code" Opera source pages in an external program that is assigned in the OS or in the browser settings for editing HTML files.
Google Chrome browser without any doubt has the best organization for viewing the original code A. By right-clicking your mouse, you can select View code A pages"and then the source code with syntax highlighting will be opened in a separate tab. Or you can select the line “View” in the same menu code element” and in the same tab will open two additional frames in which you can inspect HTML and CSS code element pages. The browser will respond to the cursor moving across lines code and, highlighting elements on the page that correspond to this section of HTML code A.
Looking through countless sites on the Internet, you can come across ones that we really like. A number of questions immediately arise. Was the site made using homemade code or some kind of CMS? What CSS styles does it have? What are its meta tags? And so on.
There are many tools that can be used to extract information about the code of a website page. But we always have the right mouse button at hand. This is what we will use, using my site as an example.
How to view the page code?
To view the source code of a site page, you need to hover your mouse over any area of the web page (except for images and links). After this, click on the right mouse button. A window with several options will open in front of us (they may differ slightly in different browsers). In the Google Chrome browser, for example, these are the commands:
- back;
- forward;
- reboot;
- save as;
- seal;
- translate to Russian;
- view page code;
- view code.
We need to click on view page code, and the html code of the site page will open in front of us.
Viewing the page code: what to pay attention to?
So, the Html page code is a numbered list of lines, each of which carries information about how this site is made. To quickly learn to understand this huge number of signs and special symbols, you need to distinguish between different sections of the code.
For example, lines of code inside the head tag contain information for search engines and webmasters. They are not displayed on the site. Here you can see what keywords this page is promoted for, how its title and description are written. Also here you can find a link, following which we will learn about the family of Google fonts used on the site.
If the site is made on CMS WordPress or Joomla, then this will also be visible here. For example, this area displays information about a WordPress theme or Joomla site template. You can see it by reading the contents of the links highlighted in blue. One link shows a website template.
For example:
//fonts.googleapis.com/css?family=Source+Sans+Pro%3A400%2C400italic%2C600&ver=4.5.3
We will see the CSS font styles of the page. In this case, the font is used. This can be seen here - font-family: 'Source Sans Pro'.
This site is optimized using the Yoast SEO plugin. This can be seen from this commented section of code:
This site is optimized with the Yoast SEO plugin v3.4.2 - https://yoast.com/wordpress/plugins/seo/
All information contained inside the body tag is displayed by the browser on the monitor screen. Here we see the html code of the page, and at the very bottom there is the Yandex Metrics script code. It is surrounded by a commented tag with the text:
/Yandex.Metrika counter
Let's sum it up
Having carried out a rather superficial analysis of the code of the main page of the site, we can draw a conclusion about what tools this page was made with. We saw on it:
- CMS WordPress;
- Google font Source Sans Pro;
- WordPress theme – Sydney;
- Yoast plugins;
- Yandex metrics counter.
Now the principle of analyzing the html code of a website page is quite clear. It is not at all necessary to keep the page you are researching open in the browser. You can save the page code to your computer using the key combinations ctrl+a, ctrl+c, ctrl+v. Paste it into any text editor (preferably Notepad++) and save it with the html extension. This way, you can study it deeper at any time and find more useful information for yourself.