Copying selected content in Chrome browser as HTML
CG Bookmarklet JavaScript solution which works well for me
CG: ... Here’s a bookmarklet you can use in Chrome to copy the exact HTML of any selected text to the clipboard:
1. Create the Bookmarklet
-
In Chrome, open Bookmarks → Bookmark Manager → Add new bookmark.
-
Give it a name, e.g.,
Copy Selection HTML
. -
In the URL field, paste the following code:
-
Save the bookmark.
2. How to Use
-
Go to any webpage.
-
Select the text you want to copy (even if it spans multiple elements).
-
Click your Copy Selection HTML bookmark.
-
You’ll see an alert:
Selection HTML copied!
-
Paste (
Ctrl+V
) into VSCode, Notepad, or any other editor.
- ✅ Only the HTML corresponding to your selected text is copied, including tags like
<b>
,<i>
,<a>
, etc.
========= end of Bookmarklet solution ========
I have given below edited extracts of some other parts of the chat.
Me: in chrome browser, how can I copy-paste selected content as HTML into another app like Notepad or VSCode (on Windows OS)
CG: Yes! You can copy HTML content from Chrome and paste it as actual HTML (not plain text) into apps like Notepad, VSCode, or other editors on Windows. Here's a detailed guide:
1. Copying HTML Source of Selected Content
Chrome doesn’t directly copy selected content as HTML by default; it copies the rendered text. To get HTML, you need to use Developer Tools:
Method A: Using “Inspect”
-
Open the webpage in Chrome.
-
Select the content you want to copy (text, images, etc.).
-
Right-click → Inspect (or press
Ctrl+Shift+I
). -
In the Elements panel, the relevant HTML for your selection will be highlighted.
-
Right-click the highlighted node → Copy → Copy outerHTML (copies the element and all its inner content).
-
Open VSCode or Notepad and paste (
Ctrl+V
).
- ✅ This will give you the HTML tags exactly as they are in the page.
Method B: Copy as “HTML” via Clipboard
If you want the selected part only (not necessarily the full element node):
-
Install a Chrome extension like “Enable Copy HTML” or “Copy as HTML”.
-
Select text on a webpage.
-
Right-click → Copy as HTML.
-
Paste into VSCode or Notepad.
- Note: Standard Notepad won’t render HTML; it will just show the code. VSCode will handle it nicely.
Method C: Use “Copy -> Copy HTML” from Context Menu
If your Chrome already has “Copy HTML” in the context menu:
-
Select the content.
-
Right-click → Copy → Copy HTML.
-
Paste into your editor.
2. Quick Tips
-
VSCode: You get syntax highlighting automatically.
-
Notepad: It’s just plain text; HTML will not render.
-
Images: If your HTML contains images, the
src
might be relative. You may need to adjust paths. -
Tables/Formatting: Copying via DevTools preserves table structure, inline styles, etc.
[IFIRC ... Method A did not work for me as it selected only one element. I did not want to install some third-party extension and so did not try Method B. Method C did not apply to my PC ('Copy HTML' was not shown in Chrome context menu). Then CG asked if I would like a bookmarklet solution to which I said yes. That's the bookmarklet code I have shared at the top of this post.]
[CG also provided 'tiny' Chrome extension code which I was very interested in. As I could check the source code of such an extension, I was ready to consider it. But the extension code provided by CG did not work for me. It could be due to some mistake I made as I have not developed a Chrome extension and so had to ask CG for step-by-step instruction which it gave. But perhaps I did not follow some instruction correctly.]
Comments
Post a Comment