How to enter the html code of a page. How to open a page's source code in a browser
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 simple document, containing the main tags.
Example 4.1. Web page source code
Heading
First paragraph.
Second paragraph.
Copy the contents 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 vary depending on HTML versions, to which they are oriented. 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. | |
Transitional XHTML 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 of errors. 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), 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 of varying levels that 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 most large print bold, subsequent level headings are smaller in size. Tags ...refer to block elements, they always start with new line, and after them other elements are displayed on next line. Additionally, white space is added before and after the title.
...refer to block elements, they always start with new line, and after them other elements are displayed on 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.
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 web masters V 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 the general "summary" styles that have been assigned to an element from css rules and the user's browser settings (his environment), and the tab is minimized.
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/further (which makes it easy to track which of the css rules has priority and is applied in 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 an element, but also move the mouse cursor to a specific one. css properties, enable it using the pop-up checkbox on the right, or disable it by unchecking the flag and viewing 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 web pages, 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 errors javascript means different browsers
Browser developers have taken care of the convenience of those who create sites that open in these same browsers, namely webmasters. They added in standard features developer tools that make it easy to open and view the source code of the site page in the browser: HTML, CSS, JavaScript (JS), get various useful data about the structure of the site, navigate it technical analysis. In general, see a lot of useful things.
Of course, these tools are used not only by website creators for work, but also ordinary users, which the source code allows you to view various useful data.
From this article you will learn how to view the source code of a website page in a browser (how to open the HTML, CSS, JavaScript code of a website).
How to open a page's source code in a browser
There are two ways to open the source code of a web page in a browser:
- Using hot keys;
- Open from context menu.
Ctrl+U– a hotkey combination to view the source code of the entire site page in a separate new window. Standard for all browsers: Google Chrome, Opera, Mozilla Firefox, Yandex browser, IE.
You can also enter the developer tools as follows:
To quickly find required code, word or text on the page, you can use the standard search hotkey combination for all browsers: Ctrl + G.
Video instruction:
View element code | explore element | inspect element
If you suddenly need to view not the entire source code, but display only a separate part of it, some area on the page, then the previous tool will not work. For this purpose, the developer tools have another function, which will be discussed below.
How to view the code of an element on a page:
You can also use keyboard shortcuts to quick access to inspect the element.
Hotkeys (buttons):
Google Chrome: Ctrl+Shift+I and Ctrl+Shift+C
Opera: Ctrl+Shift+I and Ctrl+Shift+C
Mozilla Firefox: Ctrl+Shift+I and Ctrl+Shift+C
Yandex browser: Ctrl+Shift+I and Ctrl+Shift+C
After these steps, the source code of the web page will open in the same browser window:
All HTML code will be in the large left column. A CSS styles- on the right.
Advantage this method, of course, is that the user has the opportunity to change the source code and edit styles. That is, you can edit the styles on the site and see how it will look with certain styles, without having to immediately make changes to the files located on the hosting servers. To change or add program code, you need to double click on the required fragment or plot. Of course, the code correction in the browser will not be made on the hosting servers. Therefore, in the future, in any case, you will have to copy this code and write it into files.
This video instruction describes in detail and shows how to work with the developer tools:
Just like that, just online, right in your browser, you can view the source code of the site page, get basic data about the HTML and CSS code, change and copy them, without having to download the files of this site to your computer.
By the way, inexperienced Internet users who have changed the page code and expect it to be saved will be disappointed. After all, after refreshing the page, all changes on it will disappear. This is not enough to hack the site :)
How to View Source Code on Android Phone
I would also like to note that the developer tools are available not only in the desktop version of browsers, that is, on computers and laptops. On phones and tablets (Android, iOS) you can also view the source code.
To do this, add the view-source prefix to the URL of the page being inspected:
For example:
view-source:https://site/turbo-rezhim-opera/
We have released a new book “Content Marketing in in social networks: How to get into your subscribers’ heads and make them fall in love with your brand.”
The source code of the site is a combination of HTML markup, CSS styles and JavaScript scripts, which the browser receives from the web server.
More videos on our channel - learn internet marketing with SEMANTICA
It can be compared to a set of commands given to soldiers by a commander. Imagine that the audience does not see or hear the boss. From their point of view, the military carries out actions independently. In our case, the commander is the browser, the commands are the source code, and the marching soldiers are the final result.
The site is stored on a web server, which sends the page upon user request. A request is typing a URL in the address bar, clicking a link, or clicking a submit button on a form. It doesn’t matter what language the web pages are written in or whether they include a software component. The end result The work of any server algorithm is a set of html tags and text.
The page source code is a set of data that includes:
- html markup;
- style sheet or file link;
- programs written in JavaScript or links to files with code.
These three sections are processed by the browser. For the server, this is simply the text that needs to be sent in response to the request.
Why we might need to study the source code
Everything we see, we can analyze and apply to solve certain problems that arise while working with the site, especially when optimizing it. By looking at the source code, we can:
- See the meta tags of your or someone else’s site to analyze them.
- See the presence or absence of certain elements on the site: counters, identification codes in various systems, certain scripts and other things.
- Find out the parameters of the elements: sizes, colors, fonts.
- Find the path to photos and other elements located on the page.
- Explore links from the page.
- Find problems with the code that interfere with the process of website optimization: those not addressed in separate files styles, scripts, invalid code.
These are the basic features, but in fact, by being able to read the code, you can learn a lot more about the page.
How to view the source code of a site
It will not be possible to do this completely in the form in which it is posted on the server from the browser. But you can see all the markup by clicking on the page right button mice. Here and further on Google example Chrome.
Select the “View page code” option and get the full listing in a separate tab.
It's just text that you have to analyze to understand. But you can get interactive code using the developer tools.
How to find the source code of a website page
Click on the menu icon in the browser. Most often it is on the right and looks like three dots or stripes.
In the additional tools section, select “Developer Tools”.
A window will open showing active state code. This means that when you click on the markup, the element style will appear next to it, and the selected blocks will be highlighted on the page.
In the “Source” tab you can view the contents of some files: scripts, fonts, images.
In the “Security” tab, you can check the site’s certificate.
The “Audits” tab will help you check the resource posted on the hosting.
If the location of the panel on the right is inconvenient, you can click the three dots and change it by selecting the desired item.
How to view meta tags
Every HTML document includes structure tags. Here are some of them:
- Html – the entire document.
- Head – section of service headers.
- Title – page title (displayed on the tab).
- Body – the body of the document.
- H1-H6 – page text headings.
- Article – article.
- Section - section.
- Menu – menu.
- Div – block.
- Span – string.
- P – paragraph.
- Table – table.
Elements are designed to logically delimit sections on a page; if necessary, they are designed using styles. They contain text that is somehow visible on the page. But the Head tag contains service information. Meta tags are used to indicate it. Everything that is written in them is intended for the server and search engines.
Their contents cannot be found out in any other way.
Let's pay attention to the Link tag. With its help, links to external included files are specified. If desired, you can see the contents and save to disk. To do this, move the pointer to the address and press RMB. Select "Open in new Tab".
Will open in a new tab specified file, which you can view or save.
How to view the source code of a page to debug a script
In this case, it is most convenient to open the page on local machine. If you only need to correct markup, styles and scripts, then this can be done directly from the folder. The HTML code is viewed in the same way. Here are the mistakes JavaScript code can be seen in the “Console” tab. This shows the description of the error and the line number where it occurred.
The syntax can be seen directly in the code. This is what the “Source” tab is for.
How to view the code of a specific element
For large pages with a large number of elements, it is difficult to find the necessary code in all the markup. In this case, you should use special team context menu. Move the mouse over the fragment and press RMB. Select the “View Code” command.
The same window will open, but with the focus on the selected object.
Summary
We told you what the page source code is. It is enough to master basic knowledge of HTML and CSS, and using convenient tools developer, you can debug your own HTML documents.
Reviewing the code of resources on the Internet will allow you to learn not only from your own experience, but also to use real working examples. And for SEO specialists, meta tags will be useful, the information in which can tell a lot about the site.
Skill change the page source code – useful skill for the advanced Internet user. By substituting HTML code, you can change open web page as you please. In this article we will tell you how to change page code in Google Chrome. However, in other browsers everything is done similarly, so there should not be any difficulties.
What is the HTML code of the page?
Every page you open in your browser has its own language code HTML markup. This code represents tags and text. Tags are unique labels that tell the browser how to display this or that part of the site. Text is the content of the page, what the user sees. Also, CSS styles can be connected to the page, which set appearance page elements. To change the site source code you don’t need to know HTML and CSS thoroughly, and you’ll soon see for yourself.
Why change a web page?
You can change the data on the site, change the text of the message, or take a fake screenshot. Please note that all changes are visible only to you and will disappear when you reload the page. Also the changed data will not be real. For example, if I don’t have 10 dollars, and I change it to 100, then I won’t have any more money. This is just the display of the page by the browser. Example:
After:
For example, I’ll take the same site and change the previous announcement of the article “” Opening home page in Google Chrome. I right-click on the element that I want to change, for example, the title of the announcement and select “View code”.
In the window that opens, go to the Elements tab and see the HTML code of the page. In it we need to find the text we are interested in. (underlined in red)
Now I’ll delete the old text and write in a new one.
That's all, the title of the announcement has been changed. Now I will change the announcement itself, tags and category.
You can insert another picture by changing src attribute in the img tag.