I installed Notepad++. How to make tags automatically indent especially when nesting? All the tags seem to be lining up to the left of the screen.
-
1See this solution– Willem Van OnsemJan 28, 2015 at 18:07
-
Yes. But mine gives an error it says: error detected in content please correct them before applying.– DekeJan 28, 2015 at 18:10
-
that normally means your xml code isn't valid. For instance the header is missing, or some tag isn't closed properly. In that case you shouldn't format (the original file). Since it can damage the content.– Willem Van OnsemJan 28, 2015 at 18:11
-
<!doctype> <html> <head> <title> Name of the site </title> </head> <body> <h1> Logo</h1> </body> </html> </!doctype>– DekeJan 28, 2015 at 18:15
-
3Possible duplicate of How To Auto-Format / Indent XML/HTML in Notepad++– GorvGoylAug 10, 2016 at 4:55
7 Answers
Use the XML Tools plugin for Notepad++ and then you can Auto-Indent the code with Ctrl+Alt+Shift+B .For the more point-and-click inclined, you could also go to Plugins --> XML Tools --> Pretty Print.
-
1Ctrl+Alt+Shift+B didn't work, it inserted some random text, and Pretty Print, literally did nothing (with an actual XML file even) -- it all stayed on one line, which is not well formatted, or pretty. Aug 14, 2017 at 20:15
-
XML is not HTML! In HTML, there is void elements, this allows to write either
<tag>
or<tag />
both valid in the same context. But XML is comparable to XHTML.– SandburgMay 31, 2022 at 14:38
The answers on this question are not only wrong, but dangerous. CTRL+ALT+SHIFT+B will not indent HTML but XML. Consider the following HTML code:
<span class="myClass"></span>
The function 'Notepad++ -> Plugins -> XmlTools -> Pretty print (Xml only with line breaks)' (CTRL+ALT+SHIFT+B) will transform this to:
<span class="myClass"/>
which will not be displayed correctly anymore by your browser! I strongly advice against using this function to indent HTML.
Instead use the plugin Tidy2. This will indent the HTML correctly without bad side-effects (but it will also create <html>, <head>, <body>, ...
elements around your code, if these are not there).
-
7So much this. As an amateur html/js learner I just had a terrible half an hour trying to understand why my page just didn't render at all - and the reason was that
<script src="somewhere"></script>
collapsed into<script src="somewhere"/>
– ArtalusOct 21, 2016 at 8:30 -
Hmm... it doesn't look like it works with the 64-bit version of Notepad++, which is a deal killer for me.– Saturn KJun 7, 2017 at 16:06
-
1@KeyvanSadralodabai Most of plugins (including Plugin Manager) are not yet available in x64 - if you rely on Notepad++ plugins, it's advisable to install the 32 bit version of Notepad++ instead to be able to use plugins. If that is not an option, then you have to use a different editor - i.e. Sublime Text Jun 8, 2017 at 2:08
-
1Yah you're right. Don't know why I thought it was a deal killer... it's not like it improves that much with 64 bit.– Saturn KJun 9, 2017 at 15:01
-
1For reference "Plugin Manager" (which is different from the built-in Plugin Admin) is now available as 64 bits version, but Tidy2 is still not available as 64 bits.– ÉtienneJul 11, 2019 at 9:36
Step 1: Open plugin manager in notepad++
Plugins -> Plugin Manager -> Show Plugin Manager.
Step 2:install XML Tool plugin
Search "XML TOOLS" from the "Available" option then click in install.
Now you can use shortcut key CTRL+ALT+SHIFT+B to indent the code.
-
16This answer is the same as the earlier one above and is for XML not HTML!– bytedevFeb 27, 2017 at 11:02
I have a solution for you.
Just you need to install a plugin named Indent By Fold
.
You can install this by going through
Plugins -> Plugin Manager -> Show Plugin Manager
. ORPlugins -> Plugins Admin -> chekmark Indent By Fold from list
than install
Then just select the list item and all you need is to type the first word then you got it.
you can use this plugin from a plugin in the menu bar.
-
1For HTML this produces a correct indentation, where XML Tool would produce an unbalanced indentation due to HTML<->XML differences.– jlbencNov 19, 2017 at 13:10
-
1
-
Just realized that's probably because I'm using the 64bit version of N++ Feb 20, 2019 at 20:00
-
1
-
1It only works on the code you got "on screen"the rest of the document isn't indented..– JoBeOct 17, 2020 at 19:56
Building on Constantin's answer, here's the essence of what I learned while transitioning to Notepad++ as my primary HTML editor.
Install Notepad++ 32-bit
There's no 64-bit version of Tidy2 and some other popular plugins. The 32-bit version of NPP has few practical downsides, so axe the 64-bit version.
Install the Plugin Manager
Plugin Manager isn't strictly necessary for plugin usage. It does make things much easier, though.
Plugin Manager was eliminated from the core package apparently because the developer didn't like some included attribution linking.
You may notice that Plugin Manager plugin has been removed from the official distribution. The reason is Plugin Manager contains the advertising in its dialog. I hate Ads in applications, and I ensure you that there was no, and there will never be Ads in Notepad++.
It's a manual install, but it's not difficult.
- Download the UNI (32-bit) zip package and extract it. Inside you'll see folders called plugins and updater. Each contains one file.
- Drag those two files to the respective identically-named folders in your Notepad++ installation directory. Typically that's
C:\Program Files (x86)\Notepad++
. - Restart Notepad++ and follow any install/update prompts.
Now you'll see a new entry under Plugins for Plugin Manager.
Install Tidy2 (or your preferred alternative)
In Plugin Manager, check the box for Tidy2. Click Install. Restart when prompted.
To use Tidy2, select one of the preconfigured profiles in its Plugins submenu item, or create your own.
On Notepadd++ v7.5.9 (32-bits), "Indent by fold" plugin is working fine with html content.
- Search and install in plugin manager
- Use "Plugins" > "Indent by fold" > "Reindent file"
In Notepad++ v7.8.9 you can use the Tab
key to increase the indention level, and use Shift + Tab
to decrease the indentation level.